Part Number Hot Search : 
145154 D42AD 05351 855991 C4923 DRDPB16W G4PC4 R1004
Product Description
Full Text Search
 

To Download UPD78042F Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
 Application Note
78K/0 Series
8-bit Single-chip Microcontrollers Basics (II)
PD78044F Subseries PD78044H Subseries PD780208 Subseries PD780228 Subseries
Document No. U10121EJ3V0AN00 (3rd edition) Date Published August 1997 J
(c)
Printed in Japan
1993
SUMMARY OF CONTENTS
CHAPTER 1 CHAPTER 2 CHAPTER 3 CHAPTER 4 CHAPTER 5 CHAPTER 6 CHAPTER 7 CHAPTER 8 CHAPTER 9
OVERVIEW ....................................................................................................................... SOFTWARE BASICS ....................................................................................................... SYSTEM CLOCK SWITCHING APPLICATION .............................................................. WATCHDOG TIMER APPLICATION ............................................................................... 16-BIT TIMER/EVENT COUNTER APPLICATION .........................................................
1 15 37 51 59
8-BIT TIMER/EVENT COUNTER APPLICATION ........................................................... 101 WATCH TIMER APPLICATION ....................................................................................... 117 SERIAL INTERFACE APPLICATION ............................................................................. 127 A/D CONVERTER APPLICATION ................................................................................... 215
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER ......................................................... 249 CHAPTER 11 APPLICATIONS OF 6-BIT UP/DOWN COUNTER .......................................................... 275 APPENDIX A SPD CHART DESCRIPTION ............................................................................................ 281 APPENDIX B REVISION HISTORY ......................................................................................................... 289
NOTES FOR CMOS DEVICES
1 PRECAUTION AGAINST ESD FOR SEMICONDUCTORS Note: Strong electric field, when exposed to a MOS device, can cause destruction of the gate oxide and ultimately degrade the device operation. Steps must be taken to stop generation of static electricity as much as possible, and quickly dissipate it once, when it has occurred. Environmental control must be adequate. When it is dry, humidifier should be used. It is recommended to avoid using insulators that easily build static electricity. Semiconductor devices must be stored and transported in an anti-static container, static shielding bag or conductive material. All test and measurement tools including work bench and floor should be grounded. The operator should be grounded using wrist strap. Semiconductor devices must not be touched with bare hands. Similar precautions need to be taken for PW boards with semiconductor devices on it. 2 HANDLING OF UNUSED INPUT PINS FOR CMOS Note: No connection for CMOS device inputs can be cause of malfunction. If no connection is provided to the input pins, it is possible that an internal input level may be generated due to noise, etc., hence causing malfunction. CMOS devices behave differently than Bipolar or NMOS devices. Input levels of CMOS devices must be fixed high or low by using a pull-up or pull-down circuitry. Each unused pin should be connected to VDD or GND with a resistor, if it is considered to have a possibility of being an output pin. All handling related to the unused pins must be judged device by device and related specifications governing the devices. 3 STATUS BEFORE INITIALIZATION OF MOS DEVICES Note: Power-on does not necessarily define initial status of MOS device. Production process of MOS does not define the initial operation status of the device. Immediately after the power source is turned ON, the devices with reset function have not yet been initialized. Hence, power-on does not guarantee out-pin levels, I/O settings or contents of registers. Device is not initialized until the reset signal is received. Reset operation must be executed immediately after power-on for devices having reset function.
FIP is a trademark of NEC Corporation. EEPROM and IEBus are trademarks of NEC Corporation.
The export of these products from Japan is regulated by the Japanese government. The export of some or all of these products may be prohibited without governmental license. To export or re-export some or all of these products from a country other than Japan may also be prohibited without a license from that country. Please call an NEC sales representative.
The application circuits and their parameters are for reference only and are not intended for use in actual design-ins.
The information in this document is subject to change without notice. No part of this document may be copied or reproduced in any form or by any means without the prior written consent of NEC Corporation. NEC Corporation assumes no responsibility for any errors which may appear in this document. NEC Corporation does not assume any liability for infringement of patents, copyrights or other intellectual property rights of third parties by or arising from use of a device described herein or any other liability arising from use of such device. No license, either express, implied or otherwise, is granted under any patents, copyrights or other intellectual property rights of NEC Corporation or others. While NEC Corporation has been making continuous effort to enhance the reliability of its semiconductor devices, the possibility of defects cannot be eliminated entirely. To minimize risks of damage or injury to persons or property arising from a defect in an NEC semiconductor device, customers must incorporate sufficient safety measures in its design, such as redundancy, fire-containment, and anti-failure features. NEC devices are classified into the following three quality grades: "Standard", "Special", and "Specific". The Specific quality grade applies only to devices developed based on a customer designated "quality assurance program" for a specific application. The recommended applications of a device depend on its quality grade, as indicated below. Customers must check the quality grade of each device before using it in a particular application. Standard: Computers, office equipment, communications equipment, test and measurement equipment, audio and visual equipment, home electronic appliances, machine tools, personal electronic equipment and industrial robots Special: Transportation equipment (automobiles, trains, ships, etc.), traffic control systems, anti-disaster systems, anti-crime systems, safety equipment and medical equipment (not specifically designed for life support) Specific: Aircrafts, aerospace equipment, submersible repeaters, nuclear reactor control systems, life support systems or medical equipment for life support, etc. The quality grade of NEC devices is "Standard" unless otherwise specified in NEC's Data Sheets or Data Books. If customers intend to use NEC devices for applications other than those specified for Standard quality grade, they should contact an NEC sales representative in advance. Anti-radioactive design is not implemented in this product.
M7 96. 5
Regional Information
Some information contained in this document may vary from country to country. Before using any NEC product in your application, please contact the NEC office in your country to obtain a list of authorized representatives and distributors. They will verify: * Device availability * Ordering information * Product release schedule * Availability of related technical literature * Development environment specifications (for example, specifications for third-party tools and components, host computers, power plugs, AC supply voltages, and so forth) * Network requirements In addition, trademarks, registered trademarks, export restrictions, and other legal issues may also vary from country to country.
NEC Electronics Inc. (U.S.)
Santa Clara, California Tel: 800-366-9782 Fax: 800-729-9288
NEC Electronics (Germany) GmbH
Benelux Office Eindhoven, The Netherlands Tel: 040-2445845 Fax: 040-2444580
NEC Electronics Hong Kong Ltd.
Hong Kong Tel: 2886-9318 Fax: 2886-9022/9044
NEC Electronics (Germany) GmbH
Duesseldorf, Germany Tel: 0211-65 03 02 Fax: 0211-65 03 490
NEC Electronics Hong Kong Ltd. NEC Electronics (France) S.A.
Velizy-Villacoublay, France Tel: 01-30-67 58 00 Fax: 01-30-67 58 99 Seoul Branch Seoul, Korea Tel: 02-528-0303 Fax: 02-528-4411
NEC Electronics (UK) Ltd.
Milton Keynes, UK Tel: 01908-691-133 Fax: 01908-670-290
NEC Electronics (France) S.A.
Spain Office Madrid, Spain Tel: 01-504-2787 Fax: 01-504-2860
NEC Electronics Singapore Pte. Ltd.
United Square, Singapore 1130 Tel: 253-8311 Fax: 250-3583
NEC Electronics Italiana s.r.1.
Milano, Italy Tel: 02-66 75 41 Fax: 02-66 75 42 99
NEC Electronics Taiwan Ltd. NEC Electronics (Germany) GmbH
Scandinavia Office Taeby, Sweden Tel: 08-63 80 820 Fax: 08-63 80 388 Taipei, Taiwan Tel: 02-719-2377 Fax: 02-719-5951
NEC do Brasil S.A.
Sao Paulo-SP, Brasil Tel: 011-889-1680 Fax: 011-889-1689
J96. 8
Major Changes
Page Throughout Description The following products have been added as applicable products: PD78044F, PD78044H, and PD780228 subseries, PD780206, and PD780208 The following subseries have been dropped as applicable products: PD78024 and PD78044A subseries P.37, 38 P.39, 40 P.53, 54 P.128, 129 P.216, 217 P.258, 260 P.1 The following register formats and tables are described separately according to the products: Tables 3-1 and 3-2, Figures 3-1, 3-2, 4-2, 4-3, 8-1, 8-2, 9-1, 9-2, 10-7, and 10-8
The following subseries have been added in Section 1.1. PD78075B, PD78075BY, PD780018, PD780018Y, PD780058, PD780058Y, PD78058F, PD78058FY, PD780034, PD780034Y, PD780024, PD780024Y, PD78014H, PD780964, PD780924, PD780228, PD78044H, PD78044F, PD780308, PD780308Y, PD78064B, PD78098B, PD780973, PD780805 subseries, and PD78P0914 Table 3-3 has been added. Note 2 and Caution 2 have been added to Figure 4-2. Figure 4-4 has been added. A Caution has been added to Figure 5-5. Table 8-2 has been added. Note 4 and a Caution have been added to Figure 8-3. A Caution has been added to Figure 8-9. Section 8.1 The PD6252 has been defined as a product for maintenance purposes only. Figure 9-4 has been added.
P.40 P.53 P.55 P.63 P.127 P.130 P.139 P.141 P.219
The mark
shows major revised points.
[MEMO]
PREFACE
Target users
*
This application note is for engineers who wish to understand 78K/0 Series devices and design application programs using these devices. * Target products in each subseries PD78044F subseries : PD78042F, PD78043F, PD78044F, PD78045F, PD78P048A PD78044H subseries : PD78044H, PD78045H, PD78046H, PD78P048BNote PD780208 subseries : PD780204, PD780205, PD780206, PD780208, PD78P0208 PD780228 subseries : PD780226Note, PD780228Note, PD78F0228 Note Note Under development
Objective
The purpose of this application note is to use program examples to help users to understand the basic functions of 78K/0 Series devices. The program and hardware structures published here are illustrative examples and are not designed for mass production. This application note is broadly divided into the following areas. * Overview * Software * Hardware
Organization
The following application notes are supported.
Document name Document No. Japanese English 78K/0 Series Application Note, Basics (I) 78K/0 Series Application Note, Basics (II) IEA-715 IEA-1288 PD78002, 78002Y PD78014, 78014Y PD78018F, 78018FY PD78044F PD78044H PD780208 PD780228 Describes basic functions of 78K/0 Series products, using program examples. Applicable subseries Description
U10121J This manual
78K/0 Series Application Note, Basics (III)
IEA-767
U10182E PD78054, 78054Y PD78064, 78064Y PD78078, 78078Y PD78083 PD78098 IEA-1289 All subseries of 78K/0 Series Except for PD78002 and PD78002Y subseries IEA-1301 PD78014 Only the PD78014 and PD78P014 are applicable. Describes the floating-point operation application programs of 78K/0 Series products. Describes the functions and configuration of electronic notes, using PD78014 subseries products as examples.
78K/0 Series Application IEA-718 Note, Floating-Point Operation Program PD78014 Series Application IEA-744 Note, Electronic Notes
Caution In this application note, the application examples and program listings are written for the main system clock operating at 4.19 MHz. They are not for the main system clock operating at 5.0 MHz.
Reading this note This application note is for 78K/0 Series products, but each subseries has different functions. Each subseries is described in the chapters listed in the following table. Sample applications for each subseries are given in those chapters indicated by circles.
Subseries Chapter Chapter 1 Overview Chapter 2 Software Basics Chapter 3 System Clock Switching Application Chapter 4 Watchdog Timer Application Chapter 5 16-bit Timer/Event Counter Application Chapter 6 8-bit Timer/Event Counter Application Chapter 7 Watch Timer Application Chapter 8 Serial Interface Application Chapter 9 A/D Converter Application Chapter 10 Applications of FIP Controller/Driver Chapter 11 Applications of 6-bit Up/Down Counter PD78044F o o o o o o o o o o o PD78044H o o o o o o o o o o PD780208 o o o o o o o o o o PD780228 o o o o o o -
Legend
Significance of the : data description Active-low description : Note : Caution : Remark : Number descriptions :
The left side is high-order data and the right side is low-order data. xxx (line above pin and signal names) Explanation of the note attached to the text. Contents that should be read carefully Supplemental explanation of the text Binary numbers ............. xxxx or xxxxB Decimal numbers .......... xxxx Hexadecimal numbers .. xxxxH
Application area
* Consumer product field
Related Documents The related documents indicated in this publication may include preliminary versions. However, preliminary versions are not marked as such. * Common documents
Document number Document name Japanese 78K/0 Series Application Note, Basics (II) 78K/0 Series User's Manual, Instruction 78K/0 Series Instruction Set 78K/0 Series Instruction Table U10121J U12326J U10904J U10903J English This manual IEU-1372 -
* Documents for PD78044F subseries
Document number Japanese PD78042F, 78043F, 78044F, 78045F Data Sheet PD78P048A Data Sheet PD78044F Subseries User's Manual PD78044A, 78044F Subseries Special Function Register Table U10700J U10611J U10908J U10701J English U10700E U10611E U10908E -
Document name
**
Documents for PD78044H subseries
Document number Japanese PD78044H, 78045H, 78046H Data Sheet PD78P048B Data Sheet PD78044H Subseries User's Manual U10865J To be created U11756J English U10865E To be created U11756E
Document name
* Documents for PD780208 subseries
Document number Japanese PD780204, 780205, 780206, 780208 Data Sheet PD78P0208 Data Sheet PD780208 Subseries User's Manual PD780208 Subseries Special Function Register Table U10436J U11295J U11302J U10997J English U10436E U11295E U11302E -
Document name
*
* Documents for PD780228 subseries
Document number Japanese PD780226, 780228 Data Sheet PD78F0228 Preliminary Product Information PD780228 Subseries User's Manual U11797J U11971J U12012J English U11797E U11971E U12012E
Document name
The above documents may be revised without notice. Use the latest versions when you design an application system.
[MEMO]
CONTENTS
CHAPTER 1
OVERVIEW ....................................................................................................................... 1.1 1.2 78K/0 SERIES PRODUCT DEVELOPMENT ......................................................... 78K/0 SERIES FEATURES ....................................................................................
1 1 3
CHAPTER 2
SOFTWARE BASICS ....................................................................................................... 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 DATA TRANSFER ................................................................................................... DATA COMPARISON.............................................................................................. DECIMAL ADDITION .............................................................................................. DECIMAL SUBTRACTION ...................................................................................... BINARY-TO-DECIMAL CONVERSION .................................................................. BIT OPERATION MANIPULATION INSTRUCTION .............................................. BINARY MULTIPLICATION (16 BITS x 16 BITS) .................................................. BINARY DIVISION (32 BITS/16 BITS) ...................................................................
15 15 16 17 24 26 28 29 33
CHAPTER 3
SYSTEM CLOCK SWITCHING APPLICATION .............................................................. 3.1 3.2 SWITCHING PCC AFTER RESET ......................................................................... SWITCHING DURING POWER ON/OFF ...............................................................
37 46 47
CHAPTER 4
WATCHDOG TIMER APPLICATION ............................................................................... 4.1 4.2 SETTING THE WATCHDOG TIMER MODE ......................................................... INTERVAL TIMER MODE SETTING ......................................................................
51 56 58
CHAPTER 5
16-BIT TIMER/EVENT COUNTER APPLICATION ......................................................... 5.1 5.2 5.3 INTERVAL TIMER SETTING .................................................................................. PWM OUTPUT ........................................................................................................ REMOTE CONTROL RECEPTION ........................................................................ 5.3.1 5.3.2 Remote Control Reception by a Counter Clear ........................................ Remote Control Reception by PWM Output and Free Running ..............
59 65 67 69 72 86
-i-
CHAPTER 6
8-BIT TIMER/EVENT COUNTER APPLICATION ........................................................... 101 6.1 SETTING THE INTERVAL TIMER ......................................................................... 106 6.1.1 6.1.2 6.2 Setting an 8-Bit Timer ................................................................................ 107 Setting the 16-Bit Timer ............................................................................. 109
MUSICAL SCALE GENERATION ........................................................................... 111
CHAPTER 7
WATCH TIMER APPLICATION ....................................................................................... 117 7.1 WATCH AND LED DISPLAY PROGRAM .............................................................. 119
CHAPTER 8
SERIAL INTERFACE APPLICATION ............................................................................. 127 8.1 8.2 8.3 INTERFACING WITH EEPROMTM (PD6252) ...................................................... 141 8.1.1 Communication in the 2-Wire Serial I/O Mode ......................................... 143 INTERFACING WITH THE OSD LSI (PD6451A) ................................................ 153 SBI MODE INTERFACE ......................................................................................... 158 8.3.1 8.3.2 8.4 8.4.1 8.4.2 8.5 8.5.1 8.5.2 Application as a Master CPU .................................................................... 160 Application as a Slave CPU ....................................................................... 169 Application as a Master CPU .................................................................... 174 Application as a Slave CPU ....................................................................... 178 Half-Duplex Asynchronous Communication of the 3-Wire Mode ............. 182 Half-Duplex Asynchronous Communication in the SBI Mode .................. 197
3-WIRE SERIAL I/O MODE INTERFACE .............................................................. 173
HALF-DUPLEX ASYNCHRONOUS COMMUNICATION ....................................... 182
CHAPTER 9
A/D CONVERTER APPLICATION ................................................................................... 215 9.1 9.2 9.3 9.4 LEVEL METER ........................................................................................................ 220 THERMOMETER ..................................................................................................... 229 ANALOG KEY INPUT .............................................................................................. 239 4-CHANNEL INPUT A/D CONVERSION ............................................................... 245
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER ......................................................... 249 10.1 12-DIGIT DISPLAY FOR FIP AND KEY INPUT .................................................... 262 10.1.1 12-Digit FIP Display ................................................................................... 263 10.1.2 Key Input .................................................................................................... 266 10.1.3 Description of Package .............................................................................. 268 10.1.4 Example of Use .......................................................................................... 270 10.1.5 SPD Chart .................................................................................................. 272 10.1.6 Program Listing .......................................................................................... 273 - ii -
CHAPTER 11 APPLICATIONS OF 6-BIT UP/DOWN COUNTER ......................................................... 275 11.1 1-SECOND COUNTER ........................................................................................... 277
APPENDIX A SPD CHART DESCRIPTION ........................................................................................... 281
APPENDIX B REVISION HISTORY ........................................................................................................ 289
- iii -
LIST OF FIGURES (1/4)
Figure No. 1-1. 1-2. 1-3. 1-4. 2-1. 2-2. 2-3. 2-4. 2-5. 2-6. 2-7. 2-8. 3-1. 3-2. 3-3. 3-4. 3-5. 3-6. 3-7. 3-8. 3-9. 4-1. 4-2. 4-3. 4-4. 4-5. 5-1. 5-2. Title Page 4 7 10 13 15 16 17 24 26 28 29 33
Block Diagram of the PD78044F Subseries .................................................................. Block Diagram of the PD78044H Subseries .................................................................. Block Diagram of the PD780208 Subseries .................................................................. Block Diagram of the PD780228 Subseries .................................................................. Data Exchange .................................................................................................................. Data Comparison .............................................................................................................. Decimal Addition ............................................................................................................... Decimal Subtraction .......................................................................................................... Binary-to-Decimal Conversion .......................................................................................... Bit Operation ...................................................................................................................... Binary Multiplication .......................................................................................................... Binary Division ................................................................................................................... Format of the Processor Clock Control Register (PD78044F, PD78044H, and PD780208 Subseries) ................................................ Format of the Processor Clock Control Register (PD780228 Subseries) .................... Format of the Display Mode Register 0 (PD78044F and PD78044H Subseries) ...... Format of the Display Mode Register 0 (PD780208 Subseries)................................... Format of the Display Mode Register 1 (PD78044F and PD78044H Subseries) ...... Format of the Display Mode Register 1 (PD780208 Subseries)................................... CPU Clock Switching after RESET (PD78044F Subseries) ......................................... Example of the System Clock Switching Circuit .............................................................. System Clock Switching during Power On and Off (PD78044F Subseries) ................ Format of Timer Clock Selection Register 2 (PD78044F, PD78044H, and PD780208 Subseries) ................................................ Format of the Watchdog Timer Mode Register (PD78044F, PD78044H, and PD780208 Subseries) ................................................ Format of the Watchdog Timer Mode Register (PD780228 Subseries) ....................... Format of the Watchdog Timer Clock Selection Register (Only for the PD780228 Subseries) ............................................................................... Count Timing of the Watchdog Timer .............................................................................. Format of Timer Clock Selection Register 0 .................................................................... Format of the 16-Bit Timer Mode Control Register .........................................................
39 40 41 42 44 45 46 47 48
52 53 54 55 58 60 61
- iv -
LIST OF FIGURES (2/4)
Figure No. 5-3. 5-4. 5-5. 5-6. 5-7. 5-8. 5-9. 5-10. 6-1. 6-2. 6-3. 6-4. 6-5. 6-6. 6-7. 7-1. 7-2. 7-3. 7-4. 7-5. 8-1. 8-2. 8-3. 8-4. 8-5. 8-6. 8-7. 8-8. Title Page 62 63 63 64 69 70 71 72
Format of the 16-Bit Timer Output Control Register ....................................................... Format of the Port Mode Register 3................................................................................. Format of the External Interrupt Mode Register .............................................................. Format of the Sampling Clock Selection Register ........................................................... Example of the Remote Control Receiving Circuit .......................................................... IC Output Signal for Remote Control Transmission ........................................................ Output Signal of the Receiving Preamplifier .................................................................... Sampling the Remote Control Signal ...............................................................................
Format of Timer Clock Selection Register 1 .................................................................... 102 Format of the 8-Bit Timer Mode Control Register ........................................................... 103 Format of the 8-Bit Timer Output Control Register ......................................................... 104 Format of Port Mode Register 3 ....................................................................................... 105 Count Timing of an 8-Bit Timer ........................................................................................ 106 Musical Scale Generation Circuit ..................................................................................... 111 Timer Output and Interval ................................................................................................. 111 Format of Timer Clock Selection Register 2 .................................................................... 117 Format of the Watch Timer Mode Control Register ........................................................ 118 Schematic of Watch Data ................................................................................................. 119 LED Display Timing ........................................................................................................... 120 Example Circuit of the Watch Timer ................................................................................ 120 Format of Timer Clock Selection Register 3 (PD78044F and PD780208 Subseries) ........................................................................ 128 Format of Timer Clock Selection Register 3 (PD78044H Subseries) .......................... 129 Format of Serial Operating Mode Register 0 (Only for the PD78044F and PD780208 Subseries) ................................................... 130 Format of the Serial Operating Mode Register 1 ............................................................ (PD78044F and PD780208 Subseries) ........................................................................ 132 Format of the Serial Operating Mode Register 1 (PD78044H Subseries) ................... 133 Format of the Interrupt Timing Setting Register (Only for the PD78044F and D780208 Subseries)...................................................... 134 Format of the Serial Bus Interface Control Register (Only for the PD78044F and PD780208 Subseries) ................................................... 135 Format of the Automatic Data Transmit/Receive Control Register (Only for the PD78044F and PD780208 Subseries) ................................................... 137 -v-
LIST OF FIGURES (3/4)
Figure No. 8-9. 8-10. 8-11. 8-12. 8-13. 8-14. 8-15. 8-16. 8-17. 8-18. 8-19. 8-20. 8-21. 8-22. 8-23. 8-24. 8-25. 8-26. 8-27. 9-1. 9-2. 9-3. 9-4. 9-5. 9-6. 9-7. 9-8. 9-9. 9-10. 9-11. Title Page
Format of the Automatic Data Transmit/Receive Interval Setting Register (Only for the PD78044F and PD780208 Subseries) ................................................... 138 PD6252 Pin Configuration .............................................................................................. 141 PD6252 Connection Example......................................................................................... 143 PD6252 Communication Format .................................................................................... 145 Connection Example with PD6451A .............................................................................. 153 PD6451A Communication Format .................................................................................. 153 Connection Example of the SBI Mode ............................................................................. 158 SBI Mode Communication Format ................................................................................... 159 Timed Out ACK Signal ...................................................................................................... 160 Bus Line Test .................................................................................................................... 160 Connection Example of the 3-Wire Serial I/O Mode ....................................................... 173 Communication Format of the 3-Wire Serial I/O Mode ................................................... 173 Busy Signal Output ........................................................................................................... 178 System Structure (3-Wire Mode) ...................................................................................... 182 3-Wire Mode Transmission Format .................................................................................. 183 3-Wire Mode Reception Format ....................................................................................... 184 System Structure (SBI Mode) ........................................................................................... 197 SBI Mode Transmission Format ....................................................................................... 198 SBI Mode Reception Format ............................................................................................ 199 Format of the A/D Converter Mode Register (PD78044F, PD78044H, and PD780208 Subseries) ................................................ 216 Format of the A/D Converter Mode Register (PD780228 Subseries) .......................... 217 Format of the A/D Converter Input Selection Register (PD78044F, PD78044H, and PD780208 Subseries) ................................................ 218 Format of the Analog Input Channel Specification Register (Only for the PD780228 Subseries) ............................................................................... 219 Level Meter Circuit Example ............................................................................................. 220 A/D Conversion Result and LED Display ......................................................................... 220 Conceptual Diagram of the Peak Hold ............................................................................. 221 Thermometer Circuit Example .......................................................................................... 229 Temperature and Output Characteristics ......................................................................... 230 Analog Key Input Circuit Example .................................................................................... 240 Timing Chart in the 4-Channel Scanning Mode ............................................................... 245
- vi -
LIST OF FIGURES (4/4)
Figure No. 10-1. 10-2. 10-3. 10-4. 10-5. 10-6. 10-7. 10-8. 10-9. 10-10. 10-11. 10-12. 10-13. 10-14. 10-15. 11-1. 11-2. Title Page
Format of Display Mode Register 0 (PD78044F and PD78044H Subseries) ............ 251 Format of Display Mode Register 0 (PD780208 Subseries) ......................................... 252 Format of Display Mode Register 0 (PD780228 Subseries) ......................................... 254 Format of Display Mode Register 1 (PD78044F and PD78044H Subseries) ............ 255 Format of Display Mode Register 1 (PD780208 Subseries) ......................................... 256 Format of Display Mode Register 1 (PD780228 Subseries) ......................................... 257 Format of Display Mode Register 2 (PD780208 Subseries) ......................................... 258 Format of Display Mode Register 2 (PD780228 Subseries) ......................................... 260 FIP Controller Operation Timing ....................................................................................... 261 Configuration of 12-Digit FIP Display and Key Input ....................................................... 262 Pin Layout for 9-Segment Display .................................................................................... 264 Relationship between Contents of Display Data Memory and Segment Output ........... 265 Display Example ................................................................................................................ 266 Key Interrupt Timing Chart ............................................................................................... 267 Compensating for Chattering ............................................................................................ 268 Block Diagram of 6-Bit Up/Down Counter ....................................................................... 275 Format of 6-Bit Up/Down Counter Control Register ........................................................ 276
- vii -
LIST OF TABLES
Table No. 1-1. 1-2. 1-3. 1-4. 3-1. 3-2. 3-3. 5-1. 5-2. 6-1. 8-1. 8-2. 8-3. 8-4. 8-5. 9-1. 9-2. 9-3. 10-1. Title Page 5 8 11 14
Function Overview of the PD78044F Subseries............................................................ Function Overview of the PD78044H Subseries ........................................................... Function Overview of the PD780208 Subseries ............................................................ Function Overview of the PD780228 Subseries ............................................................ Maximum Time Required to Change the CPU Clock (PD78044F, PD78044H, and PD780208 Subseries) ................................................ Maximum Time Required to Change the CPU Clock (PD780228 Subseries) ............. Relationship between the CPU Clock and Minimum Instruction Execution Time .......... Valid Time for Input Signal ............................................................................................... Valid Time of the Input Signal ..........................................................................................
37 38 40 72 86
Musical Scale and Frequencies ........................................................................................ 112 Available Serial Interface Channels in Each Subseries .................................................. 127 Serial Interface Registers ................................................................................................. 127 Description of PD6252 Pins............................................................................................ 142 PD6252 Command List ................................................................................................... 144 SBI Mode Signal List ......................................................................................................... 159 A/D Conversion Values and Temperatures ..................................................................... 231 Input Voltages and Key Codes ......................................................................................... 239 Resistances of R1 to R15 ................................................................................................. 240 Differences between PD78044F, PD78044H, PD780208, and PD780228 Subseries ...................................................................................................... 250 Comparison of SPD Symbols and Flowcharts ................................................................. 281
A-1.
- viii -
CHAPTER 1 OVERVIEW
CHAPTER 1 OVERVIEW
*
1.1 78K/0 SERIES PRODUCT DEVELOPMENT The 78K/0 series products were developed as shown below. The subseries names are indicated in frames.
Products currently being mass-produced Products under development Used for control 100-pin 100-pin 100-pin 100-pin 80-pin 80-pin 80-pin 64-pin 64-pin 64-pin 64-pin 64-pin 64-pin 64-pin 42-/44-pin Y subseries products are compatible with the I2C bus. EMI noise-reduced versions of the PD78078 A timer has been added to the PD78054 to enhance its external interface functions. ROM-less versions of the PD78078 The serial I/O of the PD78078Y has been enhanced by limiting its functions Serial I/O of the PD78054 has been enhanced. EMI noise-reduced versions of the PD78054 EMI noise-reduced versions of the PD78054 A UART and D/A converter have been added to the PD78014 to enhance its I/O. The A/D converter of the PD780024 has been enhanced. The serial I/O of the PD78018F has been enhanced. EMI noise-reduced versions of the PD78018F. EMI noise-reduced version of the PD78018F Low-voltage (1.8 V) versions of the PD78014. ROM and RAM variations have been enhanced. An A/D converter and 16-bit timer have been added to the PD78002. An A/D converter has been added to the PD78002. Basic subseries for control This product includes a UART and can operate at a low voltage (1.8 V).
PD78075B PD78075BY PD78078 PD78078Y PD78070A PD78070AY PD780018AY PD780058 PD780058YNote PD78058F PD78058FY PD78054 PD78054Y PD780034 PD780034Y PD780024 PD780024Y PD78014H PD78018F PD78018FY PD78014 PD78014Y PD780001 PD78002 PD78002Y PD78083
For inverter control
64-pin 64-pin 78K/0 Series 100-pin 100-pin 80-pin 80-pin
PD780964 PD780924
For FIPTM driving
An A/D converter of the PD780924 has been enhanced. This product includes an inverter control circuit and UART. EMI noise-reduced version. The I/O and the FIP controller/driver of the PD78044F have been enhanced. Total indication output pins: 53 The I/O and the FIP controller/driver of the PD78044H have been enhanced. Total indication output pins: 48 N-ch open-drain I/O pins have been added to the PD78044F. Total indication output pins: 34 Basic subseries for FIP driving. Total indication output pins: 34
PD780208 PD780228 PD78044H PD78044F
For LCD driving
100-pin 100-pin 100-pin
PD780308 PD78064B PD78064
PD780308Y PD78064Y
SIO of the PD78064 has been enhanced. ROM and RAM have been extended. EMI noise-reduced version of the PD78064 Basic subseries for LCD driving. These products include a UART.
Compatible with IEBusTM 80-pin 80-pin
PD78098B PD78098
EMI noise-reduced version of the PD78098 An IEBus controller has been added to the PD78054.
For meter control 80-pin
PD780973
This product includes a controller/driver for driving car meters.
For LV 64-pin
PD78P0914
This product includes the PWM output, LV digital code decoder, and Hsync counter.
Note Being planned
1
78K/0 SERIES APPLICATION NOTE
The table below shows the main differences between subseries.
Function Subseries name PD78075B PD78078 PD78070A PD780058 PD78058F For control PD78054 PD780034 PD780024 PD78014H PD78018F PD78014 PD780001 PD78002 PD78083
For inverter control
ROM capacity 32K-40 K 48K-60K 24K-60K 48K-60K 16K-60K 8K-32K 2 ch
Timer 8-bit 16-bit Watch WDT 4 ch 1 ch 1 ch 1 ch
8-bit 10-bit A/D 8 ch A/D -
8-bit D/A 2 ch
Serial interface
I/O
Minimum External VDD expansion o
3 ch (UART: 1 ch) 88 pins
1.8 V
61 pins 2 ch 3ch (time-multiplexing 68 pins UART: 1ch) 3 ch (UART: 1 ch) 69 pins
2.7 V 1.8 V 2.7 V 2.0 V
8 ch
8 ch -
-
3 ch (UART: 1 ch, time- 51 pins multiplexing 3-wire: 1ch) 2 ch 53 pins
1.8 V
8K-60K 8K-32K 8K 8K-16K 1 ch 8K-32K 3 ch Note 1 ch 8 ch 8 ch 32K-60K 48K-60K 32K-48K 16K-40K 48K-60K 32K 16K-32K 40K-60K 32K-60K 24K-32K 3 ch 1 ch 1 ch 1 ch 5 ch 2 ch (UART: 1 ch) 56 pins 4.5 V 2 ch 1 ch 1 ch 1 ch 8 ch 2 ch 3 ch (UART: 1 ch) 69 pins 2.7 V o 2 ch 1 ch 1 ch 1 ch 8 ch 2 ch 3 ch 2 ch 1 ch 1 ch 1 ch 1 ch 1 ch 2 ch 3ch (time-multiplexing 57 pins UART: 1ch) 2 ch (UART: 1 ch) 2.0 V 8 ch 8 ch 2 ch 1 ch 74 pins 72 pins 68 pins 2.7 V 4.5 V 2.7 V 1 ch 39 pins 53 pins 1 ch (UART: 1 ch) 33 pins 2 ch (UART: 2 ch) 47 pins 1.8 V 2.7 V 2.7 V o o
PD780964 PD780924 PD780208 PD780228 PD78044H PD78044F PD780308 PD78064B PD78064 PD78098B PD78098 PD780973
For meter Compatible For LV control with IEBus
For LCD driving For FIP driving
PD78P0914
32K
6 ch
-
-
1 ch
8 ch
-
-
2 ch
54 pins
4.5 V
o
Note 10-bit timer: 1 channel
2
CHAPTER 1 OVERVIEW
1.2 78K/0 SERIES FEATURES The 78K/0 Series devices are 8-bit single-chip microcontrollers ideally suited for applications in the consumer field. The PD78044F subseries are devices that implement high-speed, high-performance CPUs and have on-chip peripheral hardware, such as ROM, RAM, I/O ports, timers, serial interfaces, A/D converter, FIP controller/driver, 6-bit up/down counter, and interrupt controllers. The PD78044H subseries of devices has been implemented by adding N-ch open-drain I/O pins to the PD78044F subseries. The PD780208 subseries has an enhanced version of the FIP controller/driver of the PD78044F subseries. The PD780228 subseries has an enhanced version of the FIP controller/driver of the PD78044H subseries. The one-time PROM or EPROM versions or flash memory version, that can operate at the same low voltage as mask ROM versions, such as the PD78P048A, PD78P048B, PD78P0208, and PD78F0228 are also provided. These products are well suited for fast shift to production of application systems and small-lot production. A block diagram and an overview of the functions of each subseries are shown on the following pages.
* *
*
3
78K/0 SERIES APPLICATION NOTE
Figure 1-1. Block Diagram of the PD78044F Subseries
TO0/P30 TI0/INTP0/P00 TO1/P31 TI1/P33 TO2/P32 TI2/P34
16-bit TIMER/ EVENT COUNTER
PORT0
P00 P01-P03 P04 P10-P17
8-bit TIMER/ EVENT COUNTER1 8-bit TIMER/ EVENT COUNTER2
PORT1
PORT2
P20-P27
WATCHDOG TIMER
PORT3
P30-P37
WATCH TIMER 6-bit UP/DOWN COUNTER 78K/0 CPU CORE ROM
PORT7
P70-P74
CI0/INTP3/P03 SI0/SB0/P25 SO0/SB1/P26 SCK0/P27 SI1/P20 SO1/P21 SCK1/P22 STB/P23 BUSY/P24 ANI0/P10ANI7/P17 AVDD AVSS AVREF INTP0/TI0/P00INTP3/CI0/P03 BUZ/P36
PORT8
P80, P81
SERIAL INTERFACE 0
PORT9
P90-P97
PORT10 SERIAL INTERFACE 1
P100-P107
PORT11
P110-P117
PORT12 RAM FIP CONTROLLER/ DRIVER INTERRUPT CONTROL BUZZER OUTPUT CLOCK OUTPUT CONTROL
P120-P127
A/D CONVERTER
FIP0-FIP33 VLOAD
SYSTEM CONTROL VDD VSS IC (VPP)
PCL/P35
RESET X1 X2 XT1/P04 XT2
Remarks 1. The capacities of the internal ROM and RAM differ depending on the product. 2. The value enclosed in parentheses is applied to the PD78P048A.
4
CHAPTER 1 OVERVIEW
*
Item Internal memory ROM
Table 1-1. Function Overview of the PD78044F Subseries (1/2)
Product name PD78042F Masked ROM 16K bytes High-speed RAM Extended RAM Buffer RAM FIP display RAM General-purpose registers
Minimum instruction execution time
PD78043F
PD78044F
PD78045F
PD78P048A
One-time PROM/EPROM
24K bytes
32K bytes 1024 bytes -
40K bytes
60K bytes Note 1 1024 bytesNote 2 1024 bytes
512 bytes
64 bytes 48 bytes 8 bits x 8 x 4 banks 0.4 s/0.8 s/1.6 s/3.2 s/6.4 s (at 5.0 MHz) 122 s (at 32.768 kHz) * 16-bit operations * Multiplication/division (8 bits x 8 bits, 16 bits/8 bits) * Bit (set, reset, test, Boolean operations) * BCD conversion, etc.
For main system clock For subsystem clock
Instruction set
I/O ports (including those multiplexed with FIP pins)
* Total * CMOS input * CMOS I/O * N-ch open-drain I/O * P-ch open-drain I/O
: 68 pins : 2 pins : 27 pins : 5 pins : 16 pins
* P-ch open-drain output : 18 pins FIP controller/driver * Total : 34 pins
* Segments : 9 to 24 pins * Digits A/D converter : 2 to 16 pins
* 8-bit resolution x 8 channels * Power supply voltage: AVDD = 4.0 to 6.0 V
Serial interface
* 3-wire serial I/O, SBI, or 2-wire serial I/O mode selectable : 1 channel * 3-wire serial I/O mode (with automatic transmission/ reception function of up to 64 bytes) : 1 channel
Timer
* 16-bit timer/event counter : 1 channel * 8-bit timer/event counter : 2 channels * Watch timer * Watchdog timer * 6-bit up/down counter : 1 channel : 1 channel : 1 channel
Timer outputs
3 (one for 14-bit PWM output)
Notes 1. The memory size switching register (IMS) can be used to select 16K, 24K, 32K, 40K, or 60K bytes. 2. The IMS can be used to select 512K or 1024K bytes.
5
78K/0 SERIES APPLICATION NOTE
Table 1-1. Function Overview of the PD78044F Subseries (2/2)
Product name Item Clock output PD78042F PD78043F PD78044F PD78045F PD78P048A
19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz (at main system clock of 5.0 MHz) 32.768 kHz (at subsystem clock of 32.768 kHz)
Buzzer output Vectored interrupt factors Maskable Non-maskable Software Test input Power supply voltage Package
1.2 kHz, 2.4 kHz, 4.9 kHz (at 5.0 MHz: main system clock) Internal: 10, external: 4 Internal: 1 1 Internal: 1 VDD = 2.7 to 6.0 V * 80-pin plastic QFP (14 x 20 mm) * 80-pin ceramic WQFN: Only for the PD78P048A
6
CHAPTER 1 OVERVIEW
*
TO0/P30 TI0/INTP0/P00 TO1/P31 TI1/P33 TO2/P32 TI2/P34
Figure 1-2. Block Diagram of the PD78044H Subseries
16-bit TIMER/ EVENT COUNTER
PORT0
P00 P01-P03 P04 P10-P17
8-bit TIMER/ EVENT COUNTER1 8-bit TIMER/ EVENT COUNTER2
PORT1
PORT2
P20-P27
WATCHDOG TIMER
PORT3
P30-P37
WATCH TIMER 6-bit UP/DOWN COUNTERNote 78K/0 CPU CORE ROM
PORT7
P70-P74
CI0/INTP3/P03 SI0/SB0/P25 SO0/SB1/P26 SCK0/P27 SI1/P20 SO1/P21 SCK1/P22 STB /P23 BUSYNote/P24
Note
PORT8
P80, P81
SERIAL INTERFACE 0Note
PORT9
P90-P97
PORT10 SERIAL INTERFACE 1
P100-P107
PORT11
P110-P117
PORT12 ANI0/P10ANI7/P17 AVDD AVSS AVREF INTP0/TI0/P00INTP3/CI0/P03 BUZ/P36 RAM FIP CONTROLLER/ DRIVER INTERRUPT CONTROL BUZZER OUTPUT CLOCK OUTPUT CONTROL
P120-P127
A/D CONVERTER
FIP0-FIP33 VLOAD
SYSTEM CONTROL VDD VSS IC (VPP)
PCL/P35
RESET X1 X2 XT1/P04 XT2
Note Only for the PD78P048B Remarks 1. The capacities of the internal ROM and RAM differ depending on the product. 2. The value enclosed in parentheses is applied to the PD78P048B.
7
78K/0 SERIES APPLICATION NOTE
*
Item Internal memory ROM
Table 1-2. Function Overview of the PD78044H Subseries (1/2)
Product name PD78044H Masked ROM 32K bytes High-speed RAM Extended RAM Buffer RAM FIP display RAM General-purpose register
Minimum For main system clock instruction execution time For subsystem clock
PD78045H
PD78046H
PD78P048BNote 1 One-time PROM/EPROM
40K bytes
48K bytes
60K bytes Note 2
1024 bytes 48 bytes 8 bits x 8 x 4 banks 0.4 s/0.8 s/1.6 s/3.2 s/6.4 s (at 5.0 MHz) 122 s (at 32.768 kHz) * 16-bit operations * Multiplication/division (8 bits x 8 bits, 16 bits/8 bits) * Bit manipulations (set, reset, test, Boolean operations) * BCD conversion, etc. 1024 bytesNote 3 64 bytes
Instruction set
I/O (including those multiplexed with FIP pins)
* Total * CMOS input * CMOS I/O * N-ch open-drain I/O * P-ch open-drain I/O
: 68 lines ports : 2 lines : 19 lines : 13 lines : 16 lines
* P-ch open-drain output : 18 lines FIP controller/driver * Total : 34 lines
* Segments: 9 to 24 lines * Digits A/D converter : 2 to 16 lines * 8-bit resolution x 8 channels * Power supply voltage: AVDD = 4.0 to 6.0 V Serial interface * 3-wire serial I/O mode: 1 channel * 3-wire serial I/O, SBI, or 2-wire serial I/O mode: 1 channel
* 8-bit resolution x 8 channels * Power supply voltage: AVDD = 4.0 to 5.5 V
*
3-wire serial I/O mode with automatic transmission/reception function: 1 channel
Notes 1. Under development 2. The memory size switching register (IMS) can be used to select 32K, 40K, 48K, or 60K bytes. 3. The internal extended RAM size switching register (IXS) can be used to select 0 or 1024 bytes.
8
CHAPTER 1 OVERVIEW
Table 1-2. Function Overview of the PD78044H Subseries (2/2)
Product name Item Timer PD78044H PD78045H PD78046H PD78P048BNote * 16-bit timer/event counter: 1 channel * 8-bit timer/event counter: 2 channels * Watch timer: 1 channel * Watchdog timer: 1 channel * 6-bit up/down counter: 1 channel Timer outputs Clock output 3 lines (one for 14-bit PWM output) 19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz (at main system clock of 5.0 MHz) 32.768 kHz (at subsystem clock of 32.768 kHz) Buzzer output Vectored interrupt factors Software Test input Power supply voltage Package 1 Internal: 1 VDD = 2.7 to 5.5 V * 80-pin plastic QFP (14 x 20 mm) VDD = 2.7 to 6.0 V * 80-pin plastic QFP (14 x 20 mm) * 80-pin ceramic WQFN Maskable Non-maskable 1.2 kHz, 2.4 kHz, 4.9 kHz (at main system clock of 5.0 MHz) Internal: 8, External: 4 Internal: 1 Internal: 10, External: 4
* 16-bit timer/event counter : 1 channel * 8-bit timer/event counter : 2 channels * Watch timer * Watchdog timer : 1 channel : 1 channel
Note Under development
9
78K/0 SERIES APPLICATION NOTE
Figure 1-3. Block Diagram of the PD780208 Subseries
TO0/P30 TI0/INTP0/P00
16-bit TIMER/ EVENT COUNTER
PORT0
P00 P01-P03 P04 P10-P17
TO1/P31 TI1/P33 TO2/P32 TI2/P34
8-bit TIMER/ EVENT COUNTER1
PORT1
8-bit TIMER/ EVENT COUNTER2
PORT2
P20-P27
PORT3 WATCHDOG TIMER PORT7 WATCH TIMER PORT8 SI0/SB0/P25 SO0/SB1/P26 SCK0/P27 SERIAL INTERFACE 0 78K/0 CPU CORE ROM
P30-P37
P70-P74
P80-P87
PORT9
P90-P97
SI1/P20 SO1/P21 SCK1/P22 STB/P23 BUSY/P24 ANI0/P10ANI7/P17 AVDD AVSS AVREF INTP0/TI0/P00INTP3/P03 BUZ/P36 SERIAL INTERFACE 1
PORT10
P100-P107
PORT11
P110-P117
PORT12 RAM FIP CONTROLLER/ DRIVER INTERRUPT CONTROL BUZZER OUTPUT CLOCK OUTPUT CONTROL
P120-P127
A/D CONVERTER
FIP0-FIP52 VLOAD
SYSTEM CONTROL VDD VSS IC (VPP)
PCL/P35
RESET X1 X2 XT1/P04 XT2
Remark 1. The capacities of the internal ROM and RAM differ depending on the product. 2. The value enclosed in parentheses is applied to the PD78P0208.
10
CHAPTER 1 OVERVIEW
Table 1-3. Function Overview of the PD780208 Subseries (1/2)
Product name PD780204 Masked ROM 32K bytes High-speed RAM Extended RAM Buffer RAM FIP display RAM General-purpose registers
Minimum instruction execution time
*
Item Internal memory ROM
PD780205
PD780206
PD780208
PD78P0208
One-time PROM/EPROM
40K bytes
48K bytes
60K bytes
60K bytes Note 1
1024 bytes 64 bytes 80 bytes 8 bits x 8 x 4 banks 0.4 s/0.8 s/1.6 s/3.2 s/6.4 s (at 5.0 MHz) 122 s (at 32.768 kHz) * 16-bit operations * Multiplication/division (8 bits x 8 bits, 16 bits/8 bits) * Bit (set, reset, test, Boolean operations) * BCD conversion, etc. 1024 bytes 1024 bytesNote 2
For main system clock For subsystem clock
Instruction set
I/O ports (including those multiplexed with FIP pins)
* Total * CMOS input * CMOS I/O * N-ch open-drain I/O * P-ch open-drain I/O
: 74 pins : 2 pins : 27 pins : 5 pins : 24 pins
* P-ch open-drain output : 16 pins FIP controller/driver * Total : 53 pins
* Segments : 9 to 40 pins * Digits A/D converter : 2 to 16 pins
* 8-bit resolution x 8 channels * Power supply voltage: AVDD = 4.0 to 5.5 V
Serial interface
* 3-wire serial I/O, SBI, or 2-wire serial I/O mode selectable : 1 channel * 3-wire mode (with automatic transmission/ reception function of up to 64 bytes) : 1 channel
Timer
* 16-bit timer/event counter : 1 channel * 8-bit timer/event counter : 2 channels * Watch timer * Watchdog timer : 1 channel : 1 channel
Timer outputs
3 (one for 14-bit PWM output)
Notes 1. The memory size switching register (IMS) can be used to select 32K, 40K, 48K, or 60K bytes. 2. The internal extended RAM size switching register (IXS) can be used to select either 0 or 1024 bytes.
11
78K/0 SERIES APPLICATION NOTE
Table 1-3. Function Overview of the PD780208 Subseries (2/2)
Product name Item Clock output PD780204 PD780205 PD780206 PD780208 PD78P0208
19.5 kHz, 39.1 kHz, 78.1 kHz, 156 kHz, 313 kHz, 625 kHz (at main system clock of 5.0 MHz) 32.768 kHz (at subsystem clock of 32.768 kHz) 1.2 kHz, 2.4 kHz, 4.9 kHz (at 5.0 MHz: main system clock) Maskable Non-maskable Software Internal: 9, external: 4 Internal: 1 1 Internal: 1 VDD = 2.7 to 5.5 V * 100-pin plastic QFP (14 x 20 mm) * 100-pin ceramic WQFN: Only for the PD78P0208
Buzzer output Vectored interrupt factors Text input Power supply voltage Package
12
CHAPTER 1 OVERVIEW
*
TI1/P23
Figure 1-4. Block Diagram of the PD780228 Subseries
8-bit REMOTE CONTROLLER TIMER (TM1)
PORT0 PORT1 PORT2
P00, P01 P10-P17 P20-P25 P40-P47 P50-P57 P60-P67 P70-P77 P80-P87 P90-P97 P100-P107 FIP0-FIP47 VLOAD RESET X1 X2
TIO50/P24
8-bit PWM TIMER (TM50) 78K/0 CPU CORE
PORT4 ROM FLASH MEMORY PORT5 PORT6 PORT7 PORT8 RAM 1024 Bytes PORT9 PORT10
TIO51/P25
8-bit PWM TIMER (TM51) WATCHDOG TIMER
SCK/P20 SO/P21 SI/P22 ANI0/P10ANI7/P17 AVDD AVSS
SERIAL INTERFACE (SIO3)
A/D CONVERTER (A/D1)
FIP CONTROLLER/ DRIVER
INTP0/P00 INTP1/P01
INTERRUPT CONTROL (INT)
VDD0, VDD1, VDD2
VSS0, VSS1
IC (VPP)
SYSTEM CONTROL
Remarks 1. The internal ROM capacity differs depending on the product. 2. The value in parentheses applies to the PD78F0228 only.
13
78K/0 SERIES APPLICATION NOTE
*
Item Internal memory ROM
Table 1-4. Function Overview of the PD780228 Subseries
Product name PD780226 Masked ROM 48K bytes High-speed RAM Extended RAM FIP display RAM General-purpose registers Minimum instruction execution time Instruction set 1024 bytes 512 bytes 96 bytes 8 bits x 8 x 4 banks 0.4 s/0.8 s/1.6 s/3.2 s/6.4 s (at main system clock of 5.0 MHz) * 16-bit operations * Multiplication/division (8 bits x 8 bits, 16 bits/8 bits) * Bit (set, reset, test, Boolean operations) * BCD conversion, etc. I/O ports (including those multiplexed with FIP pins) * Total * CMOS input * CMOS I/O * N-ch open-drain I/O * P-ch open-drain I/O : 72 pins : 8 pins : 16 pins : 16 pins : 24 pins 60K bytes PD780228 PD78F0228 Flash memory 60K bytesNote
* P-ch open-drain output : 8 pins FIP controller/driver * Total : 48 pins
* 10-mA display current : 16 pins * 3-mA display current : 32 pins A/D converter * 8-bit resolution x 8 channels * Power supply voltage: AVDD = 4.5 to 5.5 V Serial interface Timer * 3-wire serial I/O mode: 1 channel * 8-bit remote controller timer : 1 channel * 8-bit PWM timer * Watchdog timer Timer outputs Vectored interrupt factors Software Power supply voltage Package 1 VDD = 4.5 to 5.5 V 100-pin plastic QFP (14 x 20 mm) Maskable Non-maskable 2 (8-bit PWM output enabled) Internal: 6, external: 4 Internal: 1 : 2 channels : 1 channel
Note The memory size switching register (IMS) can be used to select 48K or 60K bytes. Caution The PD780228 subseries is under development.
14
CHAPTER 2 SOFTWARE BASICS
CHAPTER 2 SOFTWARE BASICS
2.1 DATA TRANSFER The addresses set in the DE and HL registers are the first addresses used in data exchange. The number of bytes in the data exchange is specified in the B register. Figure 2-1. Data Exchange
Address DE+B-1 Address HL+B-1
Data exchange
DE
HL
(1) Registers used A, B, DE, HL (2) Program listing EXCH: MOV XCH XCH INCW INCW DBNZ RET A,[DE] A,[HL] A,[DE] DE HL B,$EXCH
15
78K/0 SERIES APPLICATION NOTE
2.2 DATA COMPARISON The addresses set in the DE and HL registers are the first addresses used in data comparison. The number of bytes in the data comparison is specified in the B register. When the comparison result is equal, the CY flag is set to 0. When the result is not equal, CY is set to 1. After the flag setting, processing is returned to the main program. Figure 2-2. Data Comparison
Address DE+B-1 Address HL+B-1
Data comparison
DE
HL
(1) Registers used A, B, DE, HL (2) Program listing COMP: MOV CMP BNZ INCW INCW DBNZ CLR1 BR ERROR: SET1 RTN: RET CY A,[DE] A,[HL] $ERROR DE HL B,$COMP CY RTN
16
CHAPTER 2 SOFTWARE BASICS
2.3 DECIMAL ADDITION The lowest addresses for decimal addition are specified in the DE and HL registers. The number of digits specified in BYTNUM are added. The addition result is saved in the area pointed to by the HL register. When the addition result is an overflow or an underflow, the processing branches to error processing. Have the branch address defined as `ERROR' in main program and make it a public declaration. Figure 2-3. Decimal Addition
Address DE+ BYTNUM-1 Address HL+ BYTNUM-1 Address HL+ BYTNUM-1
+
DE HL
=
HL
(1) Flowchart
BCDADD
CNumber of bytes in the decimal addition
BC-1 Number of bytes in the decimal addition not including the sign
BCDAD2
Do the augend and the addend have the same signs? Yes Decimal addition
No
Decimal subtraction
RET
17
78K/0 SERIES APPLICATION NOTE
DADDS CY0 Sign flag SFLAG0 DADDS1 A[DE]+[HL]+CY Add both the addend and augend to CY. The result is decimal-adjusted and saved in memory.
DEDE+1, HLHL+1 Increment the addend and augend addresses.
BB-1 No
B=0 Yes A[DE]+[HL]+CY Add both the addend and augend to CY. No
CY=1 Yes Sign flag SFLAG1 CY=0 DADDS3 Decimal-adjust the result.
CY=1 No A7=1 No Sign flag SFLAG=1 Yes A71 DADDS6 Save A in memory RET
Yes
Yes
No
ERROR
18
CHAPTER 2 SOFTWARE BASICS
DSUBS
Make the subtrahend positive. Sign flag0 No
Minuend<0 Yes Make the subtrahend positive. Sign flag1 DSUBS1 BC, CY0 DSUBS2
A[DE] - [HL] - CY Subtract CY from the minuend minus the subtrahend. DEDE+1, HLHL+1 Increment the minuend and subtrahend addresses
The result is decimal-adjusted and saved in memory.
CC-1 No
C=0 Yes CY=1 Yes Invert the sign flag by taking the 10's complement. DSUBS5 Result=0 No Sign flag=1 Yes Assign a negative sign to the result. No Yes No
RET
19
78K/0 SERIES APPLICATION NOTE
(2) Registers used AX, BC, DE, HL (3) Program listing ;************************************************************ ; * ; Input parameters * ; HL register: start address of the addend * ; DE register: start address of the augend * ; Output parameters * ; HL register: start address of the operation result * ; * ;************************************************************ PUBLIC PUBLIC PUBLIC EXTRN EXTBIT ; BYTNUM EQU ; CSEG BCDADD: MOV BCDAD1: MOV MOV DEC BCDAD2: MOV XCHW XCHW XCHW XOR XCHW XCHW XCHW BT CALL RET BCDAD3: CALL RET 20 !DSUBS BCDADD,BCDAD1,BCDAD2 DADDS DSUBS ERROR ; Branch address for error processing SFLAG ; Sign flag 4 ; Set the number of operand digits
C,#BYTNUM A,C B,A B
; Set the number of operand digits in the C register.
A,[HL+BYTNUM-1] ; Read in the most significant bit (sign data) of the augend AX,DE AX,HL AX,DE A,[HL+BYTNUM-1] ; Read in the most significant bit (sign data) of the augend AX,HL AX,DE AX,HL A.7,$BCDAD3 !DADDS ; Do the signs agree? ELSE subtraction processing ; THEN addition processing
CHAPTER 2 SOFTWARE BASICS
;=========================================================== ; ***** Decimal Addition ***** ;=========================================================== DADDS: CLR1 CLR1 DADDS1: MOV ADDC ADJBA MOV INCW INCW DBNZ MOV ADDC DADDS2: BNC SET1 CLR1 DADDS3: ADJBA BNC $DADDS4 BR ERROR DADDS4: BF BR DADDS5: BF SET1 DADDS6: MOV RET [HL],A SFLAG,$DADDS6 A.7 ; Set sign A.7,$DADDS5 ERROR $DADDS3 SFLAG CY ; Negative addition ; THEN set in the negative state A,[DE] A,[HL] [HL],A HL DE B,$DADDS1 A,[DE] A,[HL] ; Start addition from the least significant digit CY SFLAG
; End addition of (number-of-operand-digits - 1)
21
78K/0 SERIES APPLICATION NOTE
;================================================================= ; ***** Decimal Subtraction ***** ;================================================================= DSUBS: PUSH CLR1 MOV CLR1 MOV XCHW XCHW XCHW MOV BF CLR1 MOV SET1 DSUBS1: XCHW XCHW XCHW MOV MOV CLR1 DSUBS2: MOV SUBC ADJBS MOV INCW INCW DBNZ BNC POP PUSH MOV MOV DSUBS3: MOV SUB ADJBS MOV INCW DBNZ A,#99H A,[HL] [HL],A HL C,$DSUBS3 ; Complement operation on the subtraction result ; (subtraction-result - 99H) A,[DE] A,[HL] [HL],A HL DE C,$DSUBS2 $DSUBS5 HL HL A,B C,A AX,HL AX,DE AX,HL A,C B,A CY HL SFLAG A,[HL+BYTNUM-1] A.7 [HL+BYTNUM-1],A AX,DE AX,HL AX,DE A,[HL+BYTNUM-1] A.7,$DSUBS1 A.7 [HL+BYTNUM-1],A SFLAG
; Set the subtrahend to positive value.
; The minuend is negative. ; THEN set the minuend to a positive value. ; Set the sign to negative.
; End of the subtraction of the number of operand digits. ; THEN subtrahend > minuend
POP PUSH SET1 MOV MOV
HL HL CY A,B C,A
22
CHAPTER 2 SOFTWARE BASICS
DSUBS4: MOV ADDC ADJBA A,#0 A,[HL] ; Add 1 to the complement operation result.
MOV [HL],A INCW HL DBNZ C,$DSUBS4 MOV1 CY,SFLAG NOT1 CY MOV1 SFLAG,CY ;==================================================== ; ***** 0 Check of Operation Result ***** ;==================================================== DSUBS5: MOV MOV POP PUSH MOV DSUBS6: CMP INCW BNZ DBNZ POP RET DSUBS7: BF POP PUSH MOV SET1 MOV DSUBS8: POP RET HL SFLAG,$DSUBS8 ; Subtraction result is negative. HL ; THEN set sign HL A,[HL+BYTNUM-1] A.7 [HL+BYTNUM-1],A A,[HL] HL $DSUBS7 C,$DSUBS6 HL ; 0 check from the low-order digit A,B C,A HL HL A,#0
; End of checking all digits for 0 ; THEN subtraction result = 0
23
78K/0 SERIES APPLICATION NOTE
2.4 DECIMAL SUBTRACTION The lowest addresses for decimal subtraction are set in the DE and HL registers. Subtraction is performed on the number of digits specified in BYTNUM. The subtraction result is saved in the area specified in the HL register. Additionally, when the subtraction result is an overflow or an underflow, the processing branches to error processing. Have the branch address defined as `ERROR' in main program and make it a public declaration. This program replaces the augend and addend with the minuend and subtrahend respectively, and calls the decimal addition program. Figure 2-4. Decimal Subtraction
Address DE+ BYTNUM-1 Address HL BYTNUM-1 Address HL+ BYTNUM-1
-
DE HL
=
HL
(1) Flowchart
BCDSUB
CNumber of bytes in the decimal subtraction
Invert the sign bit of the subtrahend.
The subtrahend and minuend act as the addend and augend in decimal addition.
RET
(2) Registers used AX, BC, DE, HL
24
CHAPTER 2 SOFTWARE BASICS
(3) Program listing ;************************************************************ ; Input parameters * ; HL register: start address of the subtrahend * ; DE register: start address of the minuend * ; Output parameters * ; HL register: start address of the operation result * ; * ;************************************************************ PUBLIC BYTNUM PUBLIC BCDSUB EXTRN BCDADD,BCDAD2 ; BYTNUM EQU ; CSEG BCDSUB: MOV BCDSU1: MOV MOV DEC MOV addition. MOV1 NOT1 MOV1 MOV CALL RET CY,A.7 CY A.7,CY [HL+BYTNUM-1].A !BCDAD2 ; Invert the sign data. 4 ; Set the number of operand digits
C,#BYTNUM A,C B,A B A,[HL+BYTNUM-1]
; Set the number of operand digits in the C register.
; Set the most significant bit (sign data) of the subtrahend for use in
; Call decimal addition processing.
25
78K/0 SERIES APPLICATION NOTE
2.5 BINARY-TO-DECIMAL CONVERSION 16-bit binary data in the data memory is converted into 5-digit decimal data and saved in the data memory. The 16-bit binary data are divided by the decimal number 10 (4 times) and the conversion is based on the values of the results and remainders of these operations. Figure 2-5. Binary-to-Decimal Conversion
Low x x x High x Low 0 x 0 x 0 x 0 x 0 High x
16-bit binary (2 bytes)
5-digit decimal (5 bytes)
Example FFH is converted into decimal.
Low F F 0 High 0 Low 0 5 0 5 0 2 0 0 0 High 0
16-bit binary (2 bytes)
5-digit decimal (5 bytes)
(1) Registers used AX, BC, HL
26
CHAPTER 2 SOFTWARE BASICS
(2) Program listing PUBLIC B_DCONV DATDEC EQU 10 DSEG DS DS SADDRP 2 5 4
REGA: REGB:
; Save 16-bit binary data. ; Save 5-digit decimal data.
COLUMN EQU B_DCONV: MOVW MOV MOVW B_D1: MOV DIVUW XCH MOV INCW XCH DBNZ MOV MOV RET
AX,REGA B,#COLNUM HL,#REGB C,#DATDEC C A,C [HL],A HL A,C B,$B_D1 A,X [HL],A
27
78K/0 SERIES APPLICATION NOTE
2.6 BIT OPERATION MANIPULATION INSTRUCTION The logical product (AND) of the 1-bit flag in data memory and bit 4 in port 6 is taken. The logical sum (OR) of the result and bit 5 of port 6 is output to bit 6 of port 6. Figure 2-6. Bit Operation
FLG PORT6.4 PORT6.5
PORT6.6
(1) Program listing PUBLIC BSEG DBIT BIT_OP,FLG
FLG BIT_OP:
MOV1 AND1 OR1 MOV1 RET
CY,FLG CY,P6.4 CY,P6.5 P6.6,CY
28
CHAPTER 2 SOFTWARE BASICS
2.7 BINARY MULTIPLICATION (16 BITS x 16 BITS) The data in the multiplicand area (HIKAKE; 16 bits) and the multiplier area (KAKE; 16 bits) are multiplied. The result is saved in the operation result storage area (KOTAE). Figure 2-7. Binary Multiplication
HIKAKE+1 Multiplicand area (2 bytes) x KAKE+1 Multiplier area (2 bytes) KAKE HIKAKE
=
KOTAE+3 Operation result storage area (4 bytes)
KOTAE
Multiplication is implemented by adding the multiplicand only the number of "1" bits in the multiplier.
29
78K/0 SERIES APPLICATION NOTE
Set the data in the multiplicand area (HIKAKE) and the multiplier area (KAKE), and then call the subroutine S_KAKERU. EXTRN S_KAKERU EXTRN HIKAKE,KAKE,KOTAE MAIN: ; Multiplier . . HIKAKE=WORKA (A) ; Multiplicand data save in the multiplicand area HIKAKE+1=WORKA+1 (A) ; KAKE=WORKB (A) ; Multiplier data save in the multiplier area KAKE+1=WORKB+1 (A) ; CALL !S_KAKERU ; Multiplication routine call HL=#KOTAE ; HL <- RAM address of the operation result storage area . ; Stores the result by the indirect address transfer . . Caution Manipulate data memory in 8-bit units.
30
CHAPTER 2 SOFTWARE BASICS
(1) I/O conditions * Input parameters HIKAKE : Save the multiplicand data. KAKE : Save the multiplier data. * Output parameter KOTAE : Saves the operation result. (2) SPD chart [Multiplication subroutine]
S_KAKERU Initialization of the operation result storage area WORK1<-multiplier (low order) for (B=#0 ; B<#16 ; B++) if (B = #8) THEN WORK1<-multiplier (high order) Shift WORK1 one bit to the left. if_bit (CY = #1) THEN Add the multiplicand to the operation result storage area. if (B #15) THEN Shift the operation result storage area one bit to the left.
(3) Registers used A, B
31
78K/0 SERIES APPLICATION NOTE
(4) Program listing $PC(044A) ; PUBLIC HIKAKE,S_KAKERU,KAKE,KOTAE ; ;***************************************** ; RAM definition ;***************************************** DSEG SADDR HIKAKE: DS 2 ; Multiplicand area KAKE: DS 2 ; Multiplier area WORK1: DS 1 ; Work area KOTAE: DS 4 ; Operation result storage area ; ;***************************************** ; Multiplication ;***************************************** CSEG ; S_KAKERU: ; WORK1=KAKE+1 (A) ; Save multiplier (low order) in the work area. KOTAE=#0 ; Initialize the operation result storage area. KOTAE+1=#0 ; KOTAE+2=#0 ; KOTAE+3=#0 ; for(B=#0;B<#16;B++) (A) ; If at the end of the low-order multiplier, if(B == #8) (A) ; save the high-order multiplier in the work area. WORK1=KAKE (A) ; endif ; A=WORK1 ; Shift the multiplier one bit to the left. CLR1 CY ; ROLC A,1 ; WORK1=A ; if_bit (CY) ; If carry, KOTAE+=HIKAKE (A) ; add the multiplicand to the operation result (KOTAE+1)+=HIKAKE+1,CY (A) ; storage area. (KOTAE+2)+=#0,CY (A) ; (KOTAE+3)+=#0,CY (A) ; endif ; if(B != #15) (A) ; KOTAE+=KOTAE (A) ; Shift the operation result storage area one bit to KOTAE+1+=KOTAE+1,CY (A) ; the left. KOTAE+2+=KOTAE+2,CY (A) ; KOTAE+3+=KOTAE+3,CY (A) ; endif ; next ; RET ; END ;
32
CHAPTER 2 SOFTWARE BASICS
2.8 BINARY DIVISION (32 BITS/16 BITS) The dividend area (HIWARU; 32 bits) is divided by the divisor area (WARUM; 16 bits) and the result is saved in the operation result storage area (KOTAE). If there is a remainder, it is saved in the calculation result remainder storage area (AMARI). When the divisor is 0, an error results. Figure 2-8. Binary Division
HIWARU+3 Dividend storage area (4 bytes)
HIWARU
/
WARUM+1 WARUM Divisor area (2 bytes)
=
KOTAE+3 Operation result storage area (4 bytes)
KOTAE
AMARI+1 Calculation result remainder storage area (2 bytes)
AMARI
The dividend is shifted left starting from the high-order digit into the work area. If the contents of the work area is greater than the divisor, the divisor is subtracted from the work area, and 1 is set in the least significant bit of the dividend. In the above method, division is implemented by operating only on the number of bits in the dividend. When the divisor is 0, the error flag (F_ERR) is set.
33
78K/0 SERIES APPLICATION NOTE
Set data in the dividend area (HIWARU) and divisor area (WARUM), and then call the S_WARU subroutine. EXTRN S_WARU EXTRN HIWARU,WARUM,KOTAE EXBIT F_ERR MAIN: . . HIWARU=WORKA (A) HIWARU+1=WORKA+1 (A) WARUM=WORKB (A) WARUM+1=WORKB+1 (A) CALL !S_WARU HL=#KOTAE . . if_bit(F_ERR) Calculation error processing endif . . . ; ; ; ; ; ; ; ; ; ; ; ; ;
Save the dividend data in the dividend area Save divisor data in the divisor area Division routine call HL <- Save the RAM address of the operation result storage area
Caution Manipulate data memory in 8-bit units.
34
CHAPTER 2 SOFTWARE BASICS
(1) I/O conditions * Input parameters HIWARU : Save the dividend data. WARUM : Save the divisor data. * Output parameters KOTAE : Save the calculation result. (2) SPD chart [Division subroutine]
S_WARU
Clear operation error flag Initialize the operation result storage area and calculation result remainder storage srea. if (divisor = #0) THEN Set operation error flag if_bit (opeartion-error-falg = #0) THEN for (B=#0 ; B<#32 ; B++) Simultaneously shift the dividend and calculation result remainder one bit to the left. if (calculation-result-remainder > divisor) THEN calculation result remainder<-calculation result remainder - divisor dividend<-dividend OR #1 operation-result-storage-area<-dividend-area
(3) Registers used A, B
35
78K/0 SERIES APPLICATION NOTE
(4) Program listing $PC(044A) ; PUBLIC S_WARU,HIWARU,WARUM,F_ERR EXTRN KOTAE ; ;****************************************** ; RAM definition ;****************************************** DSEG SADDR HIWARU: DS 4 ; Dividend area WARUM: DS 2 ; Divisor area AMARI: DS 2 ; Calculation result remainder storage area BSEG F_ERR DBIT ; Operation error flag ;****************************************** ; Division ;****************************************** CSEG ; S_WARU: ; CLR1 F_ERR ; Clear operation error flag AMARI=#0 ; Clear the calculation result remainder storage area AMARI+1=#0 ; to zero KOTAE=#0 ; Clear the operation result storage area to zero KOTAE+1=#0 ; KOTAE+2=#0 ; KOTAE+3=#0 ; if(WARUM == #0) ; Divisor = 0? if(WARUM+1 == #0) ; SET1 F_ERR ; If the divisor is 0, set the operation error flag. endif ; endif ; if_bit(!F_ERR) ; Operation error? for(B=#0;B < #32;B++) (A) ; Start the 32-bit division. HIWARU+=HIWARU (A) ; Shift the dividend and the remainder one bit to the left. HIWARU+1+=HIWARU+1,CY (A) ; HIWARU+2+=HIWARU+2,CY (A) ; HIWARU+3+=HIWARU+3,CY (A) ; AMARI+=AMARI,CY (A) ; AMARI+1+=AMARI+1,CY (A) ; ; if(AMARI+1 > WARUM+1) (A) ; Remainder divisor? AMARI-=WARUM (A) ; Remainder = remainder - divisor AMARI+1-=WARUM+1,CY (A) ; HIWARU |= #1 ; Save 1 in the first bit of the dividend area. elseif_bit(Z) ; if(AMARI >= WARUM) (A) ; AMARI-=WARUM(A) ; AMARI+1-=WARUM+1,CY (A) ; HIWARU |= #1 ; endif ; endif ; next ; KOTAE=HIWARU (A) ; Save the operation result. KOTAE+1=HIWARU+1 (A) ; KOTAE+2=HIWARU+2 (A) ; KOTAE+3=HIWARU+3 (A) ; endif ; RET ; END 36
CHAPTER 3 SYSTEM CLOCK SWITCHING APPLICATION
CHAPTER 3 SYSTEM CLOCK SWITCHING APPLICATION
The 78K/0 Series can control the selection of the CPU clock and oscillator operation by rewriting the processor clock control register (PCC). The display mode registers 0 and 1 (DSPM0, DSPM1) can be used to set mode of the noise eliminator for the subsystem clock and enable or disable display operation (except for the PD780228 subseries). When the CPU clock is changed, it takes the time shown in Tables 3-1 and 3-2 from when a rewrite instruction is used to the PCC until the CPU clock is actually changed. For a while after an instruction to rewrite the PCC is issued, therefore, it cannot be determined which clock, old or new, is used by the CPU. When a main system clock is to be stopped or a STOP instruction is to be executed, a wait enough to assure instructions listed in Tables 3-1 and 3-2 have been executed is needed. Table 3-1. Maximum Time Required to Change the CPU Clock (PD78044F, PD78044H, and PD780208 Subseries)
Setting before switching
Setting after switching
CSS PCC2 PCC1 PCC0 CSS PCC2 PCC1 PCC0 CSS PCC2 PCC1 PCC0 CSS PCC2 PCC1 PCC0 CSS PCC2 PCC1 PCC0 CSS PCC2 PCC1 PCC0 CSS PCC2 PCC1 PCC0
0 0 0 0 0
0
0
0
0
0
0
1
0
0
1
0
0
0
1
1
0
1
0
0
1
x
x
x
16 instructions
16 instructions
16 instructions
16 instructions
fX/2fXT instructions (64)
0
0
1
8 instructions
8 instructions
8 instructions
8 instructions
fX/4fXT instructions (32)
0
1
0
4 instructions
4 instructions
4 instructions
4 instructions
fX/8fXT instructions (16)
0
1
1
2 instructions
2 instructions
2 instructions
2 instructions
fX/16fXT instructions (8)
1
0
0
1 instruction
1 instruction
1 instruction
1 instruction
fX/32fXT instructions (4)
1
x
x
x
1 instruction
1 instruction
1 instruction
1 instruction
1 instruction
Caution Selecting of the frequency division of the CPU clock (PCC0-PCC2) and switching from main system clock to subsystem clock (CSS: 0 -> 1) must not be performed simultaneously. However, selecting of the frequency division of the CPU clock (PCC0-PCC2) and switching from subsystem clock to main system clock (CSS: 1 -> 0) can be performed simultaneously. Remarks 1. The execution time of one instruction is the minimum instruction execution time of the CPU clock before switching. 2. Time enclosed in parentheses is required when fX = 5.0 MHz and fXT = 32.768 kHz.
37
78K/0 SERIES APPLICATION NOTE
*
Table 3-2. Maximum Time Required to Change the CPU Clock (PD780228 Subseries)
Setting before switching
Setting after switching
PCC2 PCC1 PCC0 PCC2 PCC1 PCC0 PCC2 PCC1 PCC0 PCC2 PCC1 PCC0 PCC2 PCC1 PCC0 PCC2 PCC1 PCC0 0 0 0 0 0 1 0 0 1 1 0 0 1 0 1 0 8 instructions 4 instructions 2 instructions 1 instruction 4 instructions 2 instructions 1 instruction 2 instructions 1 instruction 1 instruction 0 0 0 0 1 0 1 0 0 1 1 1 0 0
16 instructions
16 instructions 8 instructions
16 instructions 8 instructions 4 instructions
16 instructions 8 instructions 4 instructions 2 instructions
Remark The execution time of one instruction is the minimum instruction execution time of the CPU clock before switching.
38
CHAPTER 3 SYSTEM CLOCK SWITCHING APPLICATION
Figure 3-1. Format of the Processor Clock Control Register (PD78044F, PD78044H, and PD780208 Subseries)
Symbol PCC 7 6 5 CLS 4 CSS 3 0 2 1 0 Address FFFBH At reset 04H R/W R/WNote 1
MCC FRC
PCC2 PCC1 PCC0
R/W CSS PCC2 PCC1 PCC0 CPU clock (fCPU) selectionNote 2 0 0 0 0 0 1 1 0 0 0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 0 1 0 0 1 0 1 0 Setting prohibited fX fX/2 fX/22 fX/23 fX/24 fXT/2
Other than the above
R CLS 0 1
CPU clock status Main system clock Subsystem clock
R/W FRC 0 1
Selection of the feedback resistor of the subsystem clock Use on-chip feedback resistor. Do not use on-chip feedback resistor.
R/W MCC 0 1
Control of the main system clock's oscillationNote 3 Oscillation possible Oscillation stop
Notes 1. Bit 5 is read-only. 2. In the PD78044F and PD78044H subseries, FIP display is possible only when CSS is 0 and PCC2-PCC0 is 000 or 001. 3. When the CPU is operating under the subsystem clock, use MCC to stop the oscillation of the main system clock. Do not use the STOP instruction. Caution Always set 0 in bit 3. Remarks 1. fX : Oscillation frequency of the main system clock 2. fXT : Oscillation frequency of the subsystem clock
39
78K/0 SERIES APPLICATION NOTE
*
Figure 3-2. Format of the Processor Clock Control Register (PD780228 Subseries)
Symbol PCC 7 0 6 0 5 0 4 0 3 0 2 PCC2 1 PCC1 0 PCC0 Address FFFBH At reset 04H R/W R/W
PCC2 0 0 0 0 1
PCC1 0 0 1 1 0
PCC0 0 1 0 1 0
CPU clock (fCPU) selection fX fX/2 fX/22 fX/23 fX/24 Setting prohibited
Other than the above
Caution Always set 0 in bits 3 to 7. Remark fX: Oscillation frequency of the main system clock Of the instructions for the PD78044F, PD78044H, PD780208, and PD780228 subseries, the fastest requires two CPU clocks. Thus, the relationship between the CPU clock (fCPU) and minimum instruction execution time is as shown in Table 3-3. Table 3-3. Relationship between the CPU Clock and Minimum Instruction Execution Time
CPU clock (fCPU) fX f X/2 f X/22 f X/23 f X/24 f XTNote Minimum instruction execution time: 2/fCPU 0.4 s 0.8 s 1.6 s 3.2 s 6.4 s 122 s
*
Note Only for the PD78044F, PD78044H, and PD780208 subseries Remark fX = 5.0 MHz, fXT = 32.768 kHz fX: Oscillation frequency of the main system clock fXT: Oscillation frequency of the subsystem clock
40
CHAPTER 3 SYSTEM CLOCK SWITCHING APPLICATION
Figure 3-3. Format of the Display Mode Register 0 (PD78044F and PD78044H Subseries)
Symbol DSPM0 7 6 5 0 4 0 3 2 1 0 Address FFA0H At reset 00H R/W R/WNote 1
KSF DSPM06
SEGS3 SEGS2 SEGS1 SEGS0
SEGS3 SEGS2 SEGS1 SEGS0 Number of display segments 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
DSPM06 Mode setting for the noise eliminator of the
subsystem clockNote 2 0 1 KSF 0 1 2.5 MHz < fX < 5.0 MHz 1.25 MHz < fX < 2.5 MHz Timing status Display timing Key scan timing
Notes 1. Bit 7 (KSF) is read-only. 2. Specify a value in accordance with the oscillation frequency of the main system clock (fX). The noise eliminator can be used during FIP display operation. Remark fX: Oscillation frequency of the main system clock
41
78K/0 SERIES APPLICATION NOTE
Figure 3-4. Format of the Display Mode Register 0 (PD780208 Subseries) (1/2)
Symbol DSPM0
7
6
5
4
3
2
1
0
Address FFA0H
At reset 00H
R/W R/W
KSF DSPM06 DSPM05 SEGS4 SEGS3 SEGS2 SEGS1 SEGS0
R/W
SEGS4 SEGS3 SEGS2 SEGS1 SEGS0 Number of display segments (display mode 1) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
Note
Number of display outputs (display mode 2) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
39Note 40Note
Note If the total number of digits and segments exceeds 53, digits have precedence over segments.
42
CHAPTER 3 SYSTEM CLOCK SWITCHING APPLICATION
Figure 3-4. Format of the Display Mode Register 0 (PD780208 Subseries) (2/2)
Symbol DSPM0 7 6 5 4 3 2 1 0 Address FFA0H At reset 00H R/W R/WNote 1
KSF DSPM06 DSPM05 SEGS4 SEGS3 SEGS2 SEGS1 SEGS0
R/W
DSPM05 Setting of display mode
0 1
Display mode 1 (segment/character type) Display mode 2 (type that a segment extends two or more grids)
R/W
DSPM06 Mode setting for the noise eliminator of the subsystem clockNote 2
0 1
2.5 MHz < fX < 5.0 MHz 1.25 MHz < fX < 2.5 MHzNote 3
R
KSF 0 1
Timing status Display timing Key scan timing
Notes 1. Bit 7 (KSF) is read-only. 2. Specify a value in accordance with the oscillation frequency of the main system clock (fX). The noise eliminator can be used during FIP display operation. 3. When fX is used from above 1.25 MHz to 2.5 MHz, set 1 in DSPM06 before FIP display. Remark fX: Oscillation frequency of the main system clock
43
78K/0 SERIES APPLICATION NOTE
Figure 3-5. Format of the Display Mode Register 1 (PD78044F and PD78044H Subseries)
Symbol DSPM1 7 6 5 4 3 2 1 0 Address FFA1H At reset 00H R/W R/W
DIGS3 DIGS2 DIGS1 DIGS0 DIMS3 DIMS2 DIMS1 DIMS0
DIMS0 0 1
Display cycle selection 1024/fX as 1 display cycle (One display cycle is 204.8 s at 5.0 MHz.) 2048/fX as 1 display cycle (One display cycle is 409.6 s at 5.0 MHz.) Cut width of the digit signal 1/16 2/16 4/16 6/16 8/16 10/16 12/16 14/16 Number of display digits Display stop (static display)Note 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
DIMS3 DIMS2 DIMS1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1
DIGS3 DIGS2 DIGS1 DIGS0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Note When display is disabled, a port output latch can be operated to enable static display. Remark fX: Oscillation frequency of the main system clock
44
CHAPTER 3 SYSTEM CLOCK SWITCHING APPLICATION
Figure 3-6. Format of the Display Mode Register 1 (PD780208 Subseries)
Symbol DSPM1 7 6 5 4 3 2 1 0 Address FFA1H At reset 00H R/W R/W
DIGS3 DIGS2 DIGS1 DIGS0 DIMS3 DIMS2 DIMS1 DIMS0
DIMS0 0 1
Setting of display mode cycle 1024/fX as 1 display cycle (One display cycle is 204.8 s at 5.0 MHz.) 2048/fX as 1 display cycle (One display cycle is 409.6 s at 5.0 MHz.) Cut width of the FIP output signal 1/16 2/16 4/16 6/16 8/16 10/16 12/16 14/16 Number of display digits (display mode 1) DSPM05 = 0 Disabled display (static display)Note 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Number of display patterns (display mode 2) DSPM05 = 1 Disabled display (static display)Note 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
DIMS3 DIMS2 DIMS1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1
DIGS3 DIGS2 DIGS1 DIGS0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Note When display is disabled, a port output latch can be operated to enable static display. Remark fX : Oscillation frequency of the main system clock DSPM05 : Bit 5 of display mode register 0
45
78K/0 SERIES APPLICATION NOTE
3.1 SWITCHING PCC AFTER RESET By issuing the RESET signal, the slowest mode (processor clock control register(PCC) = 04H) of main system clock is selected for the CPU clock. As a result, when running at the maximum speed, PCC is rewritten and the CPU clock is set to the maximum speed (PCC = 00H). However, in order to operate at the maximum speed mode, the VDD pin voltage must be increased to the range where high-speed operation is possible and be stable. In this example, the time until the voltage increase is awaited by the watch timer (3.91-ms interval period selected). After the wait, the CPU clock switches to the maximum speed. Figure 3-7. CPU Clock Switching after RESET (PD78044F Subseries)
Working power supply VDD pin voltage ON OFF 4.5 V 2.7 V H RESET signal L CPU clock wait time HALT state 31.3 ms (217/fX : 4.19-MHz operation) 7.63 s 3.9 ms 0.48 s
After the VDD pin voltage rises above 2.7 V, the RESET signal is released 10 s later and CPU clock oscillation starts.
Before PCC switches, the VDD pin voltage increases above 4.5 V.
(1) SPD chart
Set the watch timer to 3.91 ms. WHILE : There is no interrupt request for the watch timer (! TMIF3). Clear TMIF3 Set PCC to the maximum-speed mode.
(2) Program listing ;****************************** ;* Wait setting ;****************************** TCL2=#00010000B TMC2=#00110110B ; Set the watch timer to 3.91 ms. while_bit(!TMIF3) ; 3.91 ms? endw CLR1 WTIF PCC=#00000000B ; Set the CPU clock to the maximum speed. 46
CHAPTER 3 SYSTEM CLOCK SWITCHING APPLICATION
3.2 SWITCHING DURING POWER ON/OFF The 78K/0 Series can select the subsystem clock based on the processor clock control register(PCC) setting and can operate with an ultralow power consumption. Consequently, by adding a backup power, such as a NiCd battery or super capacitor, to the system, operation can continue even when power fails. In this example, by detecting whether the power is on or off in INTP1 (select detection edge by detecting both the rising and falling edges), the on or off decision is made based on this port level and PCC switches. Figure 3-8 shows an example circuit. Figure 3-9 shows the switching timing of the system clock. Figure 3-8. Example of the System Clock Switching Circuit
+5.6 V
VDD
VSS
INTP1/P01
PD78044F
47
78K/0 SERIES APPLICATION NOTE
Figure 3-9. System Clock Switching during Power On and Off (PD78044F Subseries)
6.0 (V) VDD pin voltage 4.5 (V) 2.7 (V) ON Working power supply OFF H P01/INTP1 pin L Interrupt request generated Main system clock Interrupt request generated
System clock
Subsystem clock
Main system clock
Wait until VDD rises above 4.5 V.
(1) SPD chart
INTP1 IF : Power off (P01 = low level) THEN Set the CPU clock to the low-speed mode. User processing ELSE Set the CPU clock to the high-speed mode. User processing
48
CHAPTER 3 SYSTEM CLOCK SWITCHING APPLICATION
(2) Program listing VEP0 CSEG DW AT 08H INTP1
; INTP1 vector address setting
MOV INTM0,#00110000B ; Both edge detection mode CLR1 PMK1 EI ;**************************************** ;* Low-speed/high-speed mode setting ;**************************************** INTP1: if_bit(!P0.1) ; On-chip hardware setting (low speed) ; User processing PCC=#10010000B ; Set to low-speed mode.
; ;
else On-chip hardware setting (high speed) User processing PCC=#00000000B endif RETI ; Set to high-speed mode.
49
78K/0 SERIES APPLICATION NOTE
[MEMO]
50
CHAPTER 4 WATCHDOG TIMER APPLICATION
CHAPTER 4 WATCHDOG TIMER APPLICATION
The watchdog timer in the 78K/0 Series has the two functions of a watchdog timer mode to detect runaway operation of the microcontroller and an interval timer mode. The watchdog timer is set by timer clock selection register 2 (TCL2), watchdog timer mode register (WDTM), and watchdog timer clock selection register (WDCS).
* *
Cautions 1. WDCS is incorporated into the PD780228 subseries only. 2. The format of the registers incorporated into the PD780228 subseries differs from that of the registers incorporated into the PD78044F, PD78044H, and PD780208 subseries. When using any of the sample programs described in this chapter with the PD780228 subseries, replace the register settings with those for the PD780228 subseries.
51
78K/0 SERIES APPLICATION NOTE
Figure 4-1. Format of Timer Clock Selection Register 2 (PD78044F, PD78044H, and PD780208 Subseries)
Symbol 7 6 5 4 3 0 2 1 0 Address FF42H At reset 00H R/W R/W
TCL2 TCL27 TCL26 TCL25 TCL24
TCL22 TCL21 TCL20
TCL22 TCL21 TCL20 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1
Count clock selection Watchdog timer mode fX/23 (625 kHz) fX/24 (313 kHz) fX/25 (156 kHz) fX/26 (78.1 kHz) fX/27 (39.1 kHz) fX/28 (19.5 kHz) fX/29 (9.8 kHz) fX/211 (2.4 kHz) Interval timer mode fX/24 (313 kHz) fX/25 (156 kHz) fX/26 (78.1 kHz) fX/27 (39.1 kHz) fX/28 (19.5 kHz) fX/29 (9.8 kHz) fX/210 (4.9 kHz) fX/212 (1.2 kHz)
TCL24 Count clock selection for the watch timerNote 0 1 fX/28 (19.5 kHz) fXT (32.768 kHz)
TCL27 TCL26 TCL25 Selection of the buzzer output frequency 0 1 1 1 1 x 0 0 1 1 x 0 1 0 1 Buzzer output prohibited fX/210 (4.9 kHz) fX/211 (2.4 kHz) fX/212 (1.2 kHz) Setting prohibited
Note When a main system clock at 1.25 MHz or lower and an FIP controller/driver are used simultaneously, select f X/28 as the count clock for the watch timer. Caution When TCL2 will be rewritten with data other than identical data, rewrite after temporarily stopping timer operation. Remarks 1. 2. 3. 4. fX : Main system clock oscillation frequency fXT : Subsystem clock oscillation frequency x : Don't care The values in parentheses apply to operation with fX = 5.0 MHz or fXT = 32.768 kHz.
52
CHAPTER 4 WATCHDOG TIMER APPLICATION
*
Symbol WDTM 7 RUN 6 0
Figure 4-2. Format of the Watchdog Timer Mode Register (PD78044F, PD78044H, and PD780208 Subseries)
5 0
4
3
2 0
1 0
0 0
Address FFF9H
At reset 00H
R/W R/W
WDTM4 WDTM3
WDTM4 WDTM3 0 x
Operating mode selection for the watchdog timerNote 1 Interval timer modeNote 2 (During overflow, a maskable interrupt request is issued.)
1
0
Watchdog timer mode 1 (During overflow, a non-maskable interrupt request is issued.)
1
1
Watchdog timer mode 2 (During overflow, reset operation starts.)
RUN 0 1
Selection of watchdog timer operationNote 3 Stop count After clearing the counter, start the count.
Notes 1. When WDTM3 and WDTM4 are set to 1 once, they cannot be cleared to 0 by software. 2. In this mode, the watchdog timer start operating as an interval timer immediately after RUN is set to 1. 3. When RUN is set once to 1, it cannot be cleared to 0 by software. As a result, when the count starts, stopping by means other than RESET input is not possible. Cautions 1. When RUN is set to 1 and the watchdog timer work was cleared, the period of an actual overflow becomes a maximum of 0.5% shorter than the time set in timer clock selection register 2. 2. When watchdog timer mode 1 or 2 is being used, check that the interrupt request flag (TMIF4) is set to 0 and set WDTM4 to 1. If WDTM4 is set to 1 while TMIF4 is set to 1, a non-maskable interrupt request occurs regardless of the contents of WDTM3. Remark x: Don't care
53
78K/0 SERIES APPLICATION NOTE
*
Figure 4-3. Format of the Watchdog Timer Mode Register (PD780228 Subseries)
Symbol
7
6 0
5 0
4
3
2 0
1 0
0 0
Address FFF9H
At reset 00H
R/W R/W
WDTM RUN
WDTM4 WDTM3
WDTM4 WDTM3 Operating mode selection for the watchdog timerNote 1 0 x Interval timer mode (During overflow, a maskable interrupt request is issued.) 1 0 Watchdog timer mode 1 (During overflow, a non-maskable interrupt request is issued.) 1 1 Watchdog timer mode 2 (During overflow, reset operation starts.)
RUN 0 1
Selection of watchdog timer operationNote 2 Stop count After clearing the counter, start the count.
Notes 1. When WDTM3 and WDTM4 are set to 1 once, they cannot be cleared to 0 by software. 2. When RUN is set once to 1, it cannot be cleared to 0 by software. As a result, when the count starts, stopping by means other than RESET input is not possible. Caution When RUN is set to 1 and the watchdog timer work was cleared, the period of an actual overflow becomes a maximum of 0.5% shorter than the set time. Remark x: Don't care
54
CHAPTER 4 WATCHDOG TIMER APPLICATION
*
Symbol WDCS
Figure 4-4. Format of the Watchdog Timer Clock Selection Register (Only for the PD780228 Subseries)
7 0 6 0 5 0 4 0 3 0 2 1 0 Address FF42H At reset 00H R/W R/W
WDCS2 WDCS1 WDCS0
WDCS2 WDCS1 WDCS0 Overflow time of the watchdog/interval timer 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 212/fX (819 s) 213/fX (1.64 ms) 214/fX (3.28 ms) 215/fX (6.55 ms) 216/fX (13.1 ms) 217/fX (26.2 ms) 218/fX (52.4 ms) 220/fX (210 ms)
Remarks 1. fX: Oscillation frequency of the main system clock 2. The values in parentheses apply to operation with f X = 5.0 MHz.
55
78K/0 SERIES APPLICATION NOTE
4.1 SETTING THE WATCHDOG TIMER MODE In processing operation of the watchdog timer after detecting the runaway, there is reset processing or non-maskable interrupt servicing. Either one can be selected by the watchdog timer mode register (WDTM). When the watchdog timer mode is used, the timer must be cleared in a time interval shorter than the set runaway detection time. When the timer is not cleared, an overflow occurs and reset or interrupt servicing is executed. The runaway detection time for the watchdog timer is set in timer clock selection register 2(TCL2). In this example, 7.81 ms is selected in the runaway detection time and reset processing operation is selected when an overflow occurs. (1) SPD chart
Set 7.81 ms in the runaway detection timer of the watchdog timer The reset starting mode is set in the watchdog timer. User processing 1 Clear the watchdog timer. User processing 2 Clear the watchdog timer. User processing 3 Clear the watchdog timer.
56
CHAPTER 4 WATCHDOG TIMER APPLICATION
(2) Program listing ;******************************** ;* Watchdog timer setting ;******************************** TCL2=#00000100B WDTM=#10011000B ; User processing 1
--- ---
; Set the watchdog timer to 7.81 ms. ; Set the reset start mode.
SET1 ;
RUN
; Timer clear
User processing 2
---
---
SET1 ;
RUN
; Timer clear
User processing 3
---
---
SET1
RUN
; Timer clear
---
57
78K/0 SERIES APPLICATION NOTE
4.2 INTERVAL TIMER MODE SETTING When the interval timer mode is used, the interval time is set in timer clock selection register 2(TCL2) (interval time = 977 s to 250 ms at fX = 4.19 MHz). This interval timer sets the interrupt request flag (TMIF4) when the timer overflows. In this example, setting the three times of 977 s, 7.82 ms, and 250 ms is illustrated. Figure 4-5. Count Timing of the Watchdog Timer
Timer count INTWDT FC FD FE FF 00 01 02 03 FD FE FF 00
(1) Program listing <1> Setting 977 s TCL2 = #00000000B WDTM = #10001000B <2> Setting 7.82 ms TCL2 = #00000011B WDTM = #10001000B <3> Setting 250 ms TCL2 = #00000111B WDTM = #10001000B
; Set to 977 s. ; Select the interval timer mode.
; Set to 7.82 ms. ; Select the interval timer mode.
; Set to 250 ms. ; Select the interval timer mode.
58
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
The 16-bit timer/event counter in the 78K/0 Series supports the following functions: * Interval timer * PWM output * Pulse width measurement * External event counter * Square wave output The 16-bit timer/event counter requires the setting of the following six registers: * Timer clock selection register 0 (TCL0) * 16-bit timer mode control register (TMC0) * 16-bit timer output control register (TOC0) * Port mode register 3 (PM3) * External interrupt mode register (INTM0) * Sampling clock selection register (SCS)
59
78K/0 SERIES APPLICATION NOTE
Figure 5-1. Format of Timer Clock Selection Register 0
Symbol 7 6 5 4 3 2 1 0 Address FF40H At reset 00H R/W R/W
TCL0 CLOE TCL06 TCL05 TCL04 TCL03 TCL02 TCL01 TCL00
TCL03 TCL02 TCL01 TCL00 PCL output clock selection 0 0 1 1 1 1 1 0 1 0 0 0 0 1 0 1 0 0 1 1 0 0 1 0 1 0 1 0 fXT (32.768 kHz) fX/23 (625 kHz) fX/24 (313 kHz) fX/25 (156 kHz) fX/26 (78.1 kHz) fX/27 (39.1 kHz) fX/28 (19.5 kHz) Setting prohibited
Other than the above
Selection of the count clock TCL06 TCL05 TCL04 of the 16-bit timer register 0 0 0 0 1 0 0 1 1 0 0 1 0 1 0 TI0 (valid edge settable) fX (5.0 MHz) fX/2 (2.5 MHz) fX/22 (1.25 MHz) fX/23 (625 kHz) Setting prohibited
Other than the above
CLOE PCL output control 0 1 Output prohibited Output enabled
Cautions 1. Setting the valid edge for the TI0/INTP0 pin is performed by the external interrupt mode register (INTM0). In addition, selecting the frequency of the sampling clock is performed by the sampling clock selection register (SCS). 2. After setting TCL00 to TCL03 when PCL output is enabled, set 1 in CLOE by using a 1-bit memory manipulation instruction. 3. When the TM0 count clock is TI0 and the count value is read, read from TM0 and not from the capture register (CR01). 4. When data other than identical data will be rewritten in TCL0, rewrite after temporarily stopping timer operation. Remarks 1. 2. 3. 4. 5. 60 fX : Main system clock oscillation frequency fXT : Subsystem clock oscillation frequency TI0 : Input pin of the 16-bit timer/event counter TM0: 16-bit timer register The values in parentheses apply to operation with fX = 5.0 MHz or fXT = 32.768 kHz.
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
Figure 5-2. Format of the 16-Bit Timer Mode Control Register
Symbol TMC0
7 0
6 0
5 0
4 0
3
2
1
0
Address FF48H
At reset 00H
R/W R/W
TMC03 TMC02 TMC01 OVF0
OVF0 0 1
Overflow detection of the 16-bit timer register No overflow Overflow
TMC03 0
TMC02 0
TMC01 0
Selection of operating mode and clear mode Stop operation (Clear TM0 to 0.) PWM mode (free running)
Selection of TO0 output timing No change
Interrupt request generation Not generated
0
0
1
PWM pulse output
Generated when TM0 and CR00 match
0
1
0
Free running mode
TM0 and CR00 match.
0
1
1
TM0 and CR00 match or valid edge occurs at TI0. When there is a valid edge at TI0, clear and start. TM0 and CR00 match.
1
0
0
1
0
1
TM0 and CR00 match or valid edge occurs at TI0. When TM0 and CR00 match, clear and start. TM0 and CR00 match.
1
1
0
1
1
1
TM0 and CR00 match or valid edge occurs at TI0.
Cautions 1. Perform switching of the clear mode and TO0 output timing after timer operation is stopped (Set 000 in TMC01-TMC03.) 2. Setting the valid edge of the TI0/INTP0 pin is performed by the external interrupt mode register (INTM0). In addition, the sampling clock frequency is specified in the sampling clock selection register (SCS). 3. When PWM mode is used, after setting the PWM mode, set the data in CR00. 4. When TM0 and CR00 matched and the mode to clear and start was selected, the CR00 setting is FFFFH. When the value in TM0 changes from FFFFH to 0000H, the OVF0 flag is set to 1. 5. The 16-bit timer register begins operating when a value other than 000 (operation stop mode) is set in TMC01-TMC03. To stop the operation, set 000 in TMC01-TMC03.
61
78K/0 SERIES APPLICATION NOTE
Remarks 1. 2. 3. 4.
TO0 : TI0 : TM0 : CR00 :
Output pin of the 16-bit timer/event counter Input pin of the 16-bit timer/event counter 16-bit timer register Compare register 00
Figure 5-3. Format of the 16-Bit Timer Output Control Register
Symbol TOC0
7 0
6 0
5 0
4 0
3 LVS0
2
1
0
Address FF4EH
At reset 00H
R/W R/W
LVR0 TOC01 TOE0
TOE0 Output control of the 16-bit timer/event counter 0 1 Output prohibited (port mode) Output enabled
Mode other than PWM mode Selection of active level Control of timer output flip-flop Inverse operation Active high prohibited Inverse operation Active low enabled
PWM mode TOC01 0 1
LVS0 0 0 1 1
Setting the state of the timer output LVR0 flip-flop of the 16-bit timer/event counter 0 1 0 1 No change Reset the timer output flip-flop (0) Set the timer output flip-flop (1) Setting prohibited
Cautions 1. Always set TOC0 after timer operation has stopped. 2. 0 is read from LVS0 and LVR0 when read after setting data.
62
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
Figure 5-4. Format of the Port Mode Register 3
Symbol PM3 7 6 5 4 3 2 1 0 Address FF23H At reset FFH R/W R/W
PM37 PM36 PM35 PM34 PM33 PM32 PM31 PM30
PM3n I/O mode selection of pin P3n (n = 0 to 7) 0 1 Output mode (output buffer on) Input mode (output buffer off)
Caution When the P30/TO0 pin is used for timer output, set 0 in the output latches of PM30 and P30. Figure 5-5. Format of the External Interrupt Mode Register
Symbol 7 6 ES30 5 ES21 4 ES20 3 ES11 2 ES10 1 0 0 0 Address FFECH At reset 00H R/W R/W
INTM0 ES31
ES11 0 0 1 1
ES10 0 1 0 1
Valid edge selection for INTP0 Falling edge Rising edge Setting prohibited Both rising and falling edges
ES21 0 0 1 1
ES20 0 1 0 1
Valid edge selection for INTP1 Falling edge Rising edge Setting prohibited Both rising and falling edges
ES31 0 0 1 1
ES30 0 1 0 1
Valid edge selection for INTP2 Falling edge Rising edge Setting prohibited Both rising and falling edges
*
Caution Set the valid edge of the INTP0/TI0/P00 pin after timer operation is stopped by setting 0 in bits 1 to 3 (TMC01 to TMC03) of the 16-bit timer mode control register (TMC0). Remarks 1. The INTP0 pin also acts as the TI0/P00 pin. 2. The INTP3 pin use the falling edge only.
63
78K/0 SERIES APPLICATION NOTE
Figure 5-6. Format of the Sampling Clock Selection Register
Symbol SCS 7 0 6 0 5 0 4 0 3 0 2 0 1 0 Address FF47H At reset 00H R/W R/W
SCS1 SCS0
SCS1 SCS0 Selection of the INTP0 sampling clock 0 0 1 1 0 1 0 1 fX/2N+1 Setting prohibited fX/26 (78.1 kHz) fX/27 (39.1 kHz)
Caution fX/2 N+1 is the clock supplied to the CPU. f X/26 and fX/27 are the clocks supplied to peripheral hardware. fX/2N+1 stops in the HALT mode. Remarks 1. N: Value (N = 0 to 4) set in bits 0 to 2 (PCC0 to PCC2) in the processor clock control register (PCC) 2. fX: Main system clock oscillation frequency 3. The values in parentheses apply to operation with fX = 5.0 MHz.
64
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
5.1 INTERVAL TIMER SETTING When the interval timer is used, first the timer clock selection register (TCL0) and 16-bit timer mode control register (TMC0) are set. The clear mode of the 16-bit timer is set in TMC0. The interval time is set in TCL0. Then, the setting time and the compare register (CR00) from the count clock are set. The setting time is set by the following procedure. Setting-time = (compare-register-value + 1) x count-clock-period This example illustrates how to set the setting time of interval timer to 10 ms and 50 ms. (a) For a 10 ms interval <1> TMC0 setting Select clear and start when TM0 and CR00 match. <2> TCL0 setting A setting greater than 10 ms is possible and the fX mode with the highest resolution is selected. <3> CR00 setting 1 10 ms = (N + 1) x . 4.19 MHz . N = 10 ms x 4.19 MHz - 1 = 41899 (1) Program listing CR00=#41899 TCL0=#00010000B ; Select the count clock fX. TMC0=#00001100B ; The 16-bit timer/event counter is set to clear and start when TM0 and CR00 match.
65
78K/0 SERIES APPLICATION NOTE
(b) For a 50-ms interval <1> TMC0 setting Select clear and start when TM0 and CR00 match. <2> TCL0 setting A setting greater than 50 ms is possible and the fX /22 mode with the highest resolution is selected. <3> CR00 setting 1 50 ms = (N + 1) x 4.19 MHz/22 N = 50 ms x 4.19 MHz/2 2 - 1 .. 52374 = (1) Program listing CR00=#52374 TCL0=#00110000B ; Select the count clock fX/2 2. TMC0=#00001100B ; The 16-bit timer/event counter is set to clear and start when TM0 and CR00 match.
66
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
5.2 PWM OUTPUT When the PWM output is used, set the PWM mode in the 16-bit timer mode control register (TMC0) and the 16-bit timer/event counter in the output enabled state in the 16-bit timer output control register (TOC0). The PWM pulse width (active level) is determined by the value set in CR00. However, because PWM in the 78K/0 Series has 14-bit resolution, bits 2 to 15 become valid in the compare register (CR00). (Set bits 0 and 1 in CR00 to 0.) In this example, the basic period of the PWM mode is set to 61.0 s (2 8/fX ) and the active level is set to active-low. Also, the pulse width setting program rewrites the high-order 4 bits based on a parameter (00H to 0FH). Consequently, this application example can have a PWM output in 16 steps (CR00 = 0FFCH to FFFCH). (1) Package description PWM : PWM output subroutine name PWMOUT : Input parameter of PWM active level AX
Name PWMOUT Use PWM active-level setting Attribute SADDR Byte 1
1 level, 2 bytes * 16-bit timer/event counter * P30/TO0 * 16-bit timer/event counter setting PWM output mode TMC0=#00000010B Basic PWM period of 61.0 s TCL0=#00010000B Active-low output TOC0=#00000011B * P30 output mode PM30=0 * P30 output latch P30=0 After setting data in PWMOUT of the RAM, call the subroutine PWM.
67
78K/0 SERIES APPLICATION NOTE
(2) Use example EXTRN PWM,PWMOUT
. . .
TOC0=#00000011B TCL0=#00010000B TMC0=#00000010B
. . .
; Setting PWM output and active-low ; Select the count clock f X. ; PWM mode setting ; Input parameter setting of active level
PWMOUT=A CALL !PWM (3) SPD chart
PWM
Data read of PWMOUT Decode in the high-order 4-bit data of CR00 Set xFFCH in CR00 (x : 0 to FH).
(4) Program listing PUBLIC PWM,PWMOUT PWM_DAT DSEG SADDR PWMOUT: DS 1 ; PWM output data area (0 to 15) ;************************************ ;* PWM output (16 levels) ;************************************ PO_SEG CSEG PWM: A=PWMOUT ; Read high-order data of PWMOUT A<<=1 A<<=1 A<<=1 A<<=1 A!=#0FH ; Set low-order 12 bits in 0FFCH. X=#0FCH CR00=AX RET
68
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
5.3 REMOTE CONTROL RECEPTION Two examples of programs are introduced for remote control reception using the 16-bit timer/event counter. * The counter is cleared when a valid edge is detected by the remote control. The pulse width from the timer count value (capture register CR01) is measured until the next valid edge is detected. * The timer is allowed to run freely and the pulse width is measured from the difference in the counter between valid edges. In addition, this is synchronized to the PWM output. The remote control signal is received by a PIN light receiving diode, introduced to the PC1490 receiving preamplifier for remote control and input at pin P00/INTP0. An example remote control circuit is shown in Figure 5-7. The format of the remote control signal is shown in Figure 5-8. Figure 5-7. Example of the Remote Control Receiving Circuit
+5 V
100 F 160 k PH310 f0 IN+ PC1490 PD78044F IN- CD GND C1 VCC OUT INTP0/P00 100 k VDD
4.7 1 F
10 F
1000 pF GND
Shielded case
69
78K/0 SERIES APPLICATION NOTE
Figure 5-8. IC Output Signal for Remote Control Transmission
Time during 455-kHz oscillation
67.5 ms 108 ms 108 ms
9 ms
4.5 ms Custom Code 8 bits Custom Code 8 bits Data Code 8 bits Data Code 8 bits 27 ms 67.5 ms
13.5 ms Leader Code
27 ms
First time
9 ms 13.5 ms
4.5 ms
0.56 ms 1.125 ms 2.25 ms 0 1 Second and later times (transmission only when continuing to push the key)
1
0
0
1
9 ms 11.25 ms
2.25 ms 0.56 ms
70
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
Because the PC1490 preamplifier for remote control reception used in this circuit example is activelow, the level inputs to the PD78044F subseries become inverted data of the data transmitted by the remote control. Figure 5-9. Output Signal of the Receiving Preamplifier
H L 9 ms 4.5 ms
PC1490 output
Leader code
71
78K/0 SERIES APPLICATION NOTE
5.3.1 Remote Control Reception by a Counter Clear In this program, the valid pulse width when receiving a remote control signal is shown in Table 5-1 and the processing for each signal is described in <1> to <6>. The repeat signal of the remote control signal is valid for only the 250 ms following a valid input. Also, when a signal is input within 3 ms after a normal read, data is also invalid. Table 5-1. Valid Time for Input Signal
Signal name Leader code (low) Leader code (high) Normal Repeat Custom code/data code 0 1 Output time 9 ms 4.5 ms 2.25 ms 1.125 ms 2.25 ms Valid time 6.8 ms-11.8 ms 3 ms-5 ms 1.8 ms-3 ms 0.5 ms-1.8 ms 1.8 ms-2.5 ms
<1> Leader code (low) The interval of the 16-bit timer/event counter is set to 1.5 ms and port level sampling is performed by interrupt servicing. When the low-level input is detected five consecutive times, a leader code is judged to be present and the interval changes to 7.81 ms. Then, by having an interrupt request at the rising edge of INTP0, the low-level pulse width of the leader code is measured. Figure 5-10. Sampling the Remote Control Signal
Valid when there are 5 consecutive lows
Noise
Noise
Interval time
1.5 ms
7.81 ms
72
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
<2> Leader code (high) Based on an interrupt request at the falling edge at INTP0, the high-level pulse width of the leader code is measured by the timer counter. <3> Custom/data code Based on an interrupt request at the falling edge at INTP0, the pulse width is measured at every bit (1 period). After the 32nd bit of data is read in, a match of the inverted data and custom code is tested. Furthermore, the absence of data at the 33rd bit is verified. <4> Repeat code detection When the high level of the leader code is less than 3 ms, the pulse width is measured until a rising edge occurs at INTP0 after the leader code is output. <5> Valid period of the repeat code After valid data is input, there is sampling by interrupt servicing of the 16-bit timer/event counter (1.5 ms interval) and the valid period of 250 ms for the repeat code is measured. <6> Time out during pulse width measurement When an interrupt request (7.81 ms) of the 16-bit timer/event counter occurred during pulse width measurement, a time out occurs and the data become invalid. (1) Package description RMDATA : Saves remote control reception data RPT : Decision flag for the repeat valid interval IPDTFG : Decision flag indicating the presence of valid data RMDTOK : Decision flag indicating the presence of a valid input signal RMDTSET : Decision flag indicating the presence of an input signal Bank 0: AX, BC, HL
73
78K/0 SERIES APPLICATION NOTE

Name RPTCT RMENDCT SELMOD LD_CT RMDATA WORKP Use Repeat code valid time counter No input time counter after data input Mode selection Leader signal detection counter Valid data storage area Input signal storage area SADDRP 4 Attribute SADDR Byte 1

Name IPDTFG RMDTOK RMDTSET RPT Presence of valid data Presence of a valid input signal Presence of an input signal Decision on whether the repeat valid interval has elapsed Use
5 levels, 12 bytes * 16-bit timer/event counter * P00/INTP0 * 16-bit timer/event counter setting Time clear mode when TM0 and CR00 match Count/clock f X Compare register 00 * INTP0 sampling clock fX /27 * INTP0 high-priority interrupt request * 16-bit timer/event counter interrupt enabled * Define custom code in CSTM. This is a public declaration. * RAM clear Start using the INTP0 and INTTM0 interrupt requests.
TMC0 = #00001100B TCL0 = #00010000B CR00 = #6290 SCS = #00000011B PPR0 = 0 TMMK0 = 0
74
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
(2) Example use PUBLIC CSTM EXTRN RMDATA,RPTCT EXTBIT RPT,RMDTSET,IPDTFG CSTM EQU 9DH ; Remote control custom code
CR00=#6290 TCL0=#00010000B TMC0=#00001100B SCS=#00000011B CLR1 CLR1 CLR1 CLR1 CLR1 EI PPR0 RPT IPDTFG RMDTSET TMMK0
; Set to 1.5 ms. ; INTP0 sampling clock is fX/128. ; High priority INTP0 ; Clear flag
; Enable timer interrupt
DT_TEST: if_bit(RMDTSET) CLR1 RMDTSET if_bit(RPT) ; ; Repeat processing ; else ; ; Input present processing ; endif else if_bit(!RPT) ; ; No input present processing ; endif endif
75
78K/0 SERIES APPLICATION NOTE
(3) SPD chart
INTTM0
Select register bank 1. Enable mask interrupt IF : An input signal is present (IPDTFG) THEN IF : Valid data is present (RMDTOK) THEN IF : There is no input within the repeat valid time (250 ms). THEN ELSE Set in the repeat code invalid state. Clear RPT, IPDTFG, and RMDTOK. Count the repeat valid time. Leader low time count S_LOWCT ELSE IF : There is no input after data input (within 4.5 ms) THEN Set that valid data is present. Set RMDTOK and RMDTSET. Set to leader low detection mode S_M0SET Initialize leader low detection counter. ELSE Leader low time count S_LOWCT
S_LOWCT
IF : Leader low detection mode THEN IF : P00 = LOW THEN IF : P00 = LOW five consecutive times THEN Select leader low measurement mode. Set the 16-bit timer to 7.81 ms. Set to INTP0 rising edge detection mode. INTP0 interrupt enabled. Initialize leader low detection counter. ELSE Initialize leader detection counter. ELSE Set to leader low detection mode. S_M0SET Initialize leader detection counter.
76
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
INTP0
Select register bank 0. 100-s wait WAIT CASE : SELMOD OF : 1 Leader low measurement mode LEAD_L OF : 2 Leader high measurement mode LEAD_H OF : 3 Custom code/data read mode CDCODE OF : 4 Repeat code detection mode REPCD OF : 5 Error data detection mode ENDCHK
LEAD_L
IF : P00 = HIGH THEN 100-s wait WAIT IF : P00 = HIGH THEN Timer read CR_READ IF : 6.8 ms leader low 11.8 ms THEN Select leader high detection mode. Set to INTP0 falling edge detection mode. ELSE Set to leader low detection mode. S_M0SET
LEAD_H
IF : P00 = LOW THEN 100-s wait WAIT IF : P00 = LOW THEN Timer read CR_READ IF : 2 ms leader high 5 ms THEN IF : leader high 3 ms THEN Select the custom code/data read mode. Initialize the data storage area. ELSE Select the repeat detection mode. Set the INTP0 rising edge detection mode. ELSE Set to leader low detection mode. S_M0SET
77
78K/0 SERIES APPLICATION NOTE
CDCODE
IF : P00 = LOW THEN 100-s wait WAIT IF : P00 = LOW THEN Timer read CR_READ IF : 0.5 ms < input data 2.5 ms THEN IF : Input data 1.8 ms THEN Set CY. ELSE Clear CY. Save CY in the data storage area. IF : End of 32-bit data input THEN IF : Custom code match THEN IF : Match of inversed data of custom/data code THEN Save data code. Set in the input data present state. Set IPDTFG and clear RMDTSET, RPT, and RMDTOK. Set to error data detection mode. S_M5SET ELSE Set to leader low detection mode. S_M0SET ELSE Set to leader low detection mode. S_M0SET ELSE Set to leader low detection mode. S_M0SET
REPCD
IF : P00 = HIGH THEN 100-s wait WAIT IF : P00 = HIGH THEN IF : Valid data is present. THEN Timer read CR_READ IF : Repeat code 1 ms THEN Set in the repeat code valid state. Set RPT. Set in the end of data input state. Set to error data detection mode. S_M5SET ELSE Set to leader low detection mode. S_M0SET ELSE Set to error data detection mode. S_M5SET
78
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
ENDCHK
IF : P00 = LOW THEN 100-s wait WAIT IF : P00 = LOW THEN Set in the invalid input signal state. Clear IPDTFG and RPT. Set to leader low detection mode. S_M0SET
CR_READ
Read capture register. Stop operation of 16-bit timer. Start timer.
S_M0SET
Select the leader low detection mode. INTP0 interrupt prohibited Set the 16-bit timer to 1.5 ms
S_M5SET
Select the error data detection mode. Set the counter for the repeat valid time. Set the 16-bit timer to 1.5 ms.
79
78K/0 SERIES APPLICATION NOTE
(4) Program listing PUBLIC PUBLIC EXTRN RM_DAT DSEG RPTCT: DS RMENDCT: DS SELMOD: DS LD_CT: DS RMDATA: DS RM_DATP DSEG WORKP: DS BSEG DBIT DBIT DBIT DBIT CSEG DW CSEG DW AT 06H INTP0 AT 14H INTTM0 RPT,IPDTFG,RMDTOK,RMDTSET RMENDCT,RPTCT,SELMOD,LD_CT,RMDATA CSTM SADDR 1 ; Repeat code valid time counter 1 ; No input time counter after data input 1 ; Mode selection 1 ; Leader signal detection counter 1 ; Valid data storage area SADDRP 4
; Input signal storage area
IPDTFG RMDTOK RMDTSET RPT VEP0
; ; ; ;
Valid data is present. Input signal is valid. Input signal is present. Repeat code valid period
; INTP0 vector address setting
VETM0
; 16-bit timer vector address setting
;********************************************* ; Remote control signal timer processing ;********************************************* TM0_SEG CSEG INTTM0: SEL RB1 EI if_bit(IPDTFG) if_bit(RMDTOK) RPTCT-if(RPTCT==#0) CLR1 RPT CLR1 IPDTFG CLR1 RMDTOK endif CALL !S_LOWCT else RMENDCT-if(RMENDCT==#0) SET1 RMDTOK SET1 RMDTSET CALL !S_M0SET endif LD_CT=#5 endif else CALL !S_LOWCT endif RET1
; Interrupt enabled (INTP0) ; Is the input signal present? ; Is the data valid? ; Repeat invalid time ; Repeat code invalid state
; Set to valid data is present. ; Set to leader (low) detection mode.
80
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
S_LOWCT: if(SELMOD==#0) ; Leader (low) detection mode? if_bit(!P0.0) LD_CT-if(LD_CT==#0) SELMOD=#1 ; Leader (low) measurement mode TMC0=#00000000B CR00=#32767 ; 7.81-ms timer TMC0=#00001100B INTM0=#00000100B CLR1 PIF0 CLR1 PMK0 ; INTP0 interrupt enabled LD_CT=#5 endif else LD_CT=#5 endif else CALL !S_M0SET ; Set to leader (low) detection mode. LD_CT=#5 endif RET $EJECT ;********************************************************* ;* Remote control signal edge detection processing ;********************************************************* P0_SEG CSEG INTP0; SEL RB0 CALL !WAIT switch(SELMOD) case 1: CALL !LEAD_L break case 2: CALL !LEAD_H break case 3: CALL !CDCODE break case 4: CALL !REPCD break case 5: CALL !ENDCHK ends RETI
; 100-s wait
; Leader low detection processing
; Leader high detection processing
; Custom/data code read processing
; Repeat code detection processing
; Error data detection processing
81
78K/0 SERIES APPLICATION NOTE
;****************************** ;* Leader low detection ;****************************** LEAD_L: if_bit(P0.0) CALL !WAIT if_bit(P0.0) CALL !CR_READ if(AX>=#3354) if(AX<#18035) SELMOD=#2 INTM0=#00000000B else CALL !S_M0SET endif else CALL !S_M0SET endif endif endif RET $EJECT ;***************************** ;* Leader high detection ;***************************** LEAD_H: if_bit(!P0.0) CALL !WAIT if_bit(!P0.0) CALL !CR_READ if(AX>=#5710-160/2) if(AX<#20132-160/2) if(AX>#11743-160/2) SELMOD=#3 WORKP=#0000H (WORKP)+2=#8000H else SELMOD=#4 INTM0=#00000100B endif else CALL !S_M0SET endif else CALL !S_M0SET endif endif endif RET $EJECT ; Level check P0.0 = 0:noise ; 100-s wait ; ; ; ; ; Timer value read 6.8 ms - (1.5 ms x 4) 11.8 ms - (1.5 ms x 5) Leader high detection mode INTP0 falling edge
; Set to leader (low) detection mode.
; Set to leader (low) detection mode.
; Level check P0.0 = 1:noise ; 100-s wait ; Timer value read ; 1.8 ms - 100 s x 2 - 160 clocks (edge detection -> timer start) ; 5 ms - 100 s x 2 - 160 clocks (edge detection -> timer start) ; Custom/data code (3 ms - 100 s x 2)? ; Data read mode ; Initialize work area. ; Set most significant bit to 1 (for verifying the end of data). ; Repeat detection mode ; INTP0 rising
; Set to leader (low) detection mode.
; Set to leader (low) detection mode.
82
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
;******************************* ;* Custom/data code read ;******************************* CDCODE: if_bit(!P0.0) ; Level check P0.0 = 1:noise CALL !WAIT ; 100-s wait if_bit(!P0.0) CALL !CR_READ ; Timer value read if(AX>=#1257-190/2) ; 0.5 ms - 100 s x 2 - 190 clocks (edge detection -> timer start) if(AX<#9646-190/2) ; 2.5 ms - 100 s x 2 - 190 clocks (edge detection -> timer start) if(AX>=#6710-190/2); 1.8 ms - 100 s x 2 - 190 clocks (edge detection -> timer start) SET1 CY else CLR1 CY endif HL=#WORKP+3 ; Set work area address. C=#4 ; Set number of digits in work area. WKSHFT: A=[HL] ; 1-bit data save RORC A,1 ; 1-bit shift [HL]=A HL-DBNZ C,$WKSHFT ; Completed the shift of all digits. if_bit(CY) ; Is 32-bit input finished? if(WORKP+0==#CSTM) (A) ; Custom code check A^=WORKP+1 if(A==#0FFH) ; Custom code inverted data check A=WORKP+2 A^=WORKP+3 ; Data code inverted data check if(A==#0FFH) ; Save input data. RMDATA=WORKP+2 (A) ; Set in the input data present state. SET1 IPDTFG CLR1 RMDTSET CLR1 RPT CLR1 RMDTOK CALL !S_M5SET else ; Set to leader (low) detection mode. CALL !S_M0SET endif else ; Set to leader (low) detection mode. CALL !S_M0SET endif else CALL !S_M0SET
83
78K/0 SERIES APPLICATION NOTE
endif endif else CALL !S_M0SET endif else CALL !S_M0SET endif endif endif RET $EJECT ;******************************* ;* Repeat code detection ;******************************* REPCD: if_bit(P0.0) CALL !WAIT if_bit(P0.0) if_bit(RMDTOK) CALL !CR_READ if(AX<=#3354-190/2) SET1 RPT CLR1 RMDTOK CLR1 RMDTSET CALL !S_M5SET else CALL !S_M0SET endif else CALL !S_M0SET endif endif endif RET $EJECT
; Set to leader (low) detection mode.
; Set to leader (low) detection mode.
; Level check P0.0 = 0:noise ; 100-s wait ; Is valid data present? ; Timer value read ; 1 ms - 100 s x 2 - 190 clocks (edge detection -> timer start) ; Input signal check after the end of data
; Set to leader (low) detection mode.
; Set to leader (low) detection mode.
84
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
;****************************************** ;* Error data detection ;****************************************** ENDCHK: if_bit(!P0.0) ; Level check P0.0 = 1:noise CALL !WAIT ; 100-s wait if_bit(!P0.0) CLR1 !PDTFG ; Error data input CLR1 RPT ; Input signal invalid CALL !S_M0SET ; Set to leader (low) detection mode. endif endif RET ;****************************************** ;* 100-s wait ;****************************************** WAIT: B=#(838-14-12-8)/12 ; CALL(14), RET(12), MOV(8) WAITCT: ; 100-s setting DBNZ B,$WAITCT ; 1 instruction, 12 clocks RET ;****************************************** ;* Leader (low) detection mode setting ;****************************************** S_M0SET: TMC0=#00000000B CR00=#6290 TCL0=#00010000B ; Set timer to 1.5 ms. TMC0=#00001100B SELMOD=#0 ; Leader (low) detection mode SET1 PMK0 RET ;****************************************** ;* Error data detection mode setting ;****************************************** S_M5SET: RPTCT=#173 ; Counter for 250-ms measurement SELMOD=#5 ; End of data input mode RMENDCT=#3 ; Counter for no input verification TMC0=#00000000B ; Operation stopped CR00=#6290 ; Set to 1.5 ms. TMC0=#00001100B RET ;****************************************** ;* Read timer count value ;****************************************** CR_READ: AX=CR01 TMC0=#00000000B ; Stop operation TMC0=#00001100B ; Timer start RET
85
78K/0 SERIES APPLICATION NOTE
5.3.2 Remote Control Reception by PWM Output and Free Running In this program, the valid pulse widths when the remote control signal is the received signal are shown in Table 5-2. The processing methods for each signal are explained in <1> to <6>. Table 5-2. Valid Time of the Input Signal
Signal name Leader code (low) Leader code (high) Normal Repeat Custom code/data code 0 1 Output time 9 ms 4.5 ms 2.25 ms 1.125 ms 2.25 ms Valid time 3 ms-10 ms 3 ms-5 ms 1.8 ms-3 ms 0.5 ms-1.8 ms 1.8 ms-2.5 ms
<1> Leader code (low) An interrupt request during the detection of the falling edge of INTP0 causes the 16-bit capture register (CR01) value to be saved in memory. When the rising edge occurs, the pulse width is measured from the difference with the 16-bit compare register (CR00). <2> Leader code (high) Based on an interrupt request due to the falling edge of INTP0, the pulse width during the high level of the leader code is measured by the timer count. <3> Custom/data code Based on an interrupt request due to the falling edge of INTP0, the pulse width is measured for each bit (1 period). After the 32nd bit of data is read in, test for a match of the inverse data and custom code. Furthermore, the absence of a 33rd bit of data is verified. <4> Repeat code detection When the high level of the leader code is less than 3 ms, the pulse width is measured until the rising edge of INTP0 after the leader code output. <5> Valid time for repeat code After valid data input, the overflow flag (OVF0) of the 16-bit timer/event counter is tested in the main program. A valid time of 250 ms for the repeat code is measured. <6> Time out during pulse width measurement The OVF0 of the 16-bit timer/event counter during pulse width measurement is tested in the main program. When detected twice, a time out occurs and data becomes invalid. Because the 16-bit timer/event counter in this example is operated in the PWM output mode, by linking the program shown in Section 5.2, remote control reception and PWM output can be simultaneously executed.
86
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
(1) Package description TIM_PRO : Name of subroutine for timer overflow processing RMDATA : Saves remote control reception data. RPT : Decision flag for the repeat valid interval IPDTFG : Decision flag indicating the presence of valid data RMDTOK : Decision flag indicating the presence of a valid input signal RMDTSET : Decision flag indicating the presence of an input signal OVSENS : Timer overflow detection flag in INTP0 processing Bank 0: AX, BC, HL
Name RPTCT RMENDCT SELMOD LD_CT RMDATA TO_CNT CR01_NP CR01_OP WORKP Use Time counter for valid repeat code No input time counter after data input Mode selection Leader signal detection counter Valid data storage area Timer overflow detection counter Newest timer counter value storage area Previous timer counter value storage area Input signal storage area 4 SADDRP 2 Attribute SADDR Byte 1

Name IPDTFG RMDTOK RMDTSET RPT TO_FLG OVSENS Presence of valid data Presence of valid input signal Presence of input signal Decision on whether the repeat valid interval has elapsed Timer overflow present Timer overflow detection in INTP0 processing Use
5 levels, 11 bytes * 16-bit timer/event counter * P00/INTP0 * P30/TO0
87
78K/0 SERIES APPLICATION NOTE
* 16-bit timer/event counter setting PWM output mode Basic PWM period of 61.0 s Active-low output * P30 output mode * INTP0 sampling clock fX /27 * INTP0 high-priority interrupt request * INTP0 interrupt enabled * Define custom code in CSTM. This is * Clear RAM
TMC0 = #00000010B TCL0 = #00010000B TOC0 = #00000011B PM30 = 0 SCS = #00000011B PPR0 = 0 PMK0 = 0 a public declaration.
* Test OVF0 of the 16-bit timer/event counter. When OVF0 is set, call the TIM_PRO subroutine. * Start using an interrupt request based on the edge detection of the remote control signal.
88
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
(2) Example use PUBLIC EXTRN EXTBIT EQU CSTM RMDATA,RPTCT,PWM,PWMOUT,TIM_PR0 RPT,RMDTSET,IPDTFG,TO_FLG,OVSENS 9DH ; Custom code ; ; ; ; ; Setting of PWM output and active low Select fX count clock. Overflow present in PWM mode. INTP0 falling edge INTP0 sampling clock of fX/128
CSTM
TOC0=#00000011B TCL0=#00010000B TMC0=#00000010B INTM0=#00000000B SCS=#00000011B CLR1 CLR1 CLR1 CLR1 CLR1 EI DT_TEST: if_bit(OVSENS) CLR1 OVSENS CALL !TIM_PR0 elseif_bit(OVF0) CLR1 OVF0 SET1 TO_FLG CALL !TIM_PR0 endif if_bit(RMDTSET) CLR1 RMDTSET if_bit(RPT) ; ; ; ; ; ; else if_bit(!RPT) ; ; ; No input present processing endif endif MOV PWMOUT.A CALL !PWM Repeat processing else Input present processing endif PPR0 RPT IPDTFG RMDTSET PMK0
; INTP0 high priority ; Clear flag
; INTP0 interrupt enabled
; Timer overflow detection in INTP0 processing
; Timer overflow is present.
89
78K/0 SERIES APPLICATION NOTE
(3) SPD chart
TIM_PRO
IF : An input signal is present. THEN IF : There is valid data. THEN IF : Repeat code invalid period. THEN Set in the repeat code invalid state. Clear RPT, IPDTFG, and RMDTOK. Timer overflow check TO_CHK ELSE IF : There is no input after the end of data input (within 61.0 s x 2) THEN Set to valid data is present. Set RMDTOK and RMDTSET. Set to leader low detection mode. S_M0SET ELSE Timer overflow check TO_CHK
TO_CHK
IF : Leader low detection mode. THEN Set to no timer overflow ELSE Timer overflow count IF : Timer overflows twice THEN Set to leader low detection mode. S_M0SET
INTP0
Select register bank 0. 100-s wait WAIT CASE : SELMOD OF : 0 Leader low detection mode RM_STA OF : 1 Leader low measurement mode LEAD_L OF : 2 Leader high measurement mode LEAD_H OF : 3 Custom code/data read mode CDCODE OF : 4 Repeat code detection mode REPCD OF : 5 Error data detection mode ENDCHK
90
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
RM_STA
IF : P00 = LOW THEN 100-s wait WAIT IF : P00 = LOW THEN Save data in capture register into memory. Select leader low measurement mode 1. Set to the INTP0 rising edge detection mode.
LEAD_L
IF : P00 = HIGH THEN 100-s wait WAIT IF : P00 = LOW THEN Timer read PW_CT IF : 3 ms leader low 10ms THEN Select the leader high detection mode. Set to INTP0 falling edge detection mode. ELSE Set to leader low detection mode. S_M0SET
LEAD_H
IF : P00 = LOW THEN 100-s wait WAIT IF : P00 = LOW THEN Timer read PW_CT IF : 2 ms leader high 5 ms THEN IF : Leader high 3 ms THEN Select custom code/data read mode. Initialize the data storage area. ELSE Select the repeat detection mode. Set to INTP0 rising edge detection mode. ELSE Set to leader low detection mode. S_M0SET
91
78K/0 SERIES APPLICATION NOTE
CDCODE
IF : P00 = LOW THEN 100-s wait WAIT IF : P00 = LOW THEN Timer read CR_READ IF : 0.5 ms < input data 2.5 ms THEN IF : input data 1.8 ms THEN Set CY. ELSE Clear CY. Save CY in data storage area. IF : End of 32-bit data input. THEN IF : Custom code match THEN IF : Inverse data of custom/data code match THEN Save data code. Set in the input data present state. Set IPDTFG and clear RMDTSET, RPT, and RMDTOK. Set to error data detection mode. S_M5SET ELSE Set to leader low detection mode S_M0SET ELSE Set to leader low detection mode S_M0SET ELSE Set to leader low detection mode S_M0SET
REPCD
IF : P00 = HIGH THEN 100-s wait WAIT IF : P00 = HIGH THEN IF : Valid data is present. THEN Timer read PW_CT IF : Repeat code 1 ms THEN Set in the repeat code valid state. Set RPT. Set in the end of data input state. Set to error data detection mode. S_M5SET ELSE Set to leader low detection mode. S_M0SET ELSE Set to error data detection mode. S_M5SET
92
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
ENDCHK
IF : P00 = LOW THEN 100-s wait WAIT IF : P00 = LOW THEN Set the input signal in the invalid state. Clear IPDTFG and RPT. Set to leader low detection mode. S_M0SET
PW_CT
IF : OVF occurs after edge detection. THEN IF : OVF generated < interrupt reception processing time or more (65 clocks) THEN Set to timer overflow present. Read capture register. Subtract the capture register value from the previous value. IF : Borrow generated in the subtraction result (CY= 1) THEN IF : There is timer overflow (TO_FLG = 1) THEN Clear CY flag. ELSE IF : There is timer overflow (TO_FLG = 1) THEN Set CY flag. Save the value in the capture register into memory.
S_M0SET
Select the leader low detection mode. Clear TO_FLG. Set to INTP0 falling edge detection mode.
S_M5SET
Select the error data detection mode. Set the counter for repeat valid time.
93
78K/0 SERIES APPLICATION NOTE
(4) Program listing PUBLIC PUBLIC PUBLIC EXTRN RM_DAT DSEG RPTCT: DS RMENDCT:DS SELMOD: DS LD_CT DS RMDATA: DS TO_CNT: DS RM_DATP DSEG CR01_NP:DS CR01_OP:DS WORKP: DS BSEG DBIT DBIT DBIT DBIT DBIT DBIT CSEG DW AT 06H INTP0 TIM_PRO,RPT,IPDTFG,RMDTOK,RMDTSET RMENDCT,RPTCT,SELMOD,LD_CT,RMDATA TO_FLG,OVSENS CSTM SADDR 1 1 1 1 1 1 SADDRP 2 2 4
; ; ; ; ; ;
Counter for repeat code valid time Counter for no input time after data input Mode selection Leader signal detection counter Valid data storage area Timer overflow counter
; Newest timer counter value storage area ; Previous timer counter value storage area ; Input signal storage area
!PDTFG RMDTOK RMDTSET RPT TO_FLG OVSENS VEP0
; ; ; ; ; ;
Valid data is present. Input signal is valid. Input signal is present. Repeat code valid period Timer overflow is present. Timer overflow detection in INTP0 processing
; Setting of the INTP0 vector address
$EJECT ;*********************************************** ;* Remote control signal timer processing ;*********************************************** TM0_SEG CSEG TIM_PRO: if_bit(IPDTFG) ; Is an input signal present? if_bit(RMDTOK) ; Is the data valid? RPTCT-if(RPTCT==#0) ; Repeat invalid time CLR1 RPT ; Repeat code invalid state CLR1 !PDTFG CLR1 RMDTOK endif else RMENDCT-if(RMENDCT==#0) SET1 RMDTOK ; Set to valid data is present. SET1 RMDTSET CALL !S_M0SET ; Set to leader (low) detection mode. endif endif else CALL !TO_CHK ; Timer overflow check endif RET 94
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
TO_CHK: if(SELMOD==#0) CLR1 TO_FLG else TO_CNT++ if(TO_CNT==#2) CALL !S_M0SET ; Set to starting edge detection mode. endif endif RET $EJECT ;********************************************** ;* Remote control signal edge detection ;********************************************** P0_SEG CSEG INTP0: SEL RB0 CALL !WAIT ; 100-s wait
switch(SELMOD) case 0: CALL break case 1: CALL break case 2: CALL break case 3: CALL break case 4: CALL break case 5: CALL ends RETI
!RM_STA
; Starting edge detection
!LEAD_L
; Leader low detection
!LEAD_H
; Leader high detection
!CDCODE
; Custom/data code read
!REPCD
; Repeat code detection
!ENDCHK
; Error data detection
;********************************************** ;* Starting edge detection ;********************************************** RM_STA: CLR1 TO_FLG ; Timer counter starts if_bit(!P0.0) ; Level check P0.0 = 1:noise CALL !WAIT ; 100-s wait if_bit(!P0.0) CR01_OP=CR01 (AX) ; Save capture register. SELMOD=#1 ; Leader low detection mode INTM0=#00000100B ; INTP0 rising edge TO_CNT=#0 endif endif RET 95
78K/0 SERIES APPLICATION NOTE
;****************************** ;* Leader low detection ;****************************** LEAD_L: if_bit(P0.0) CALL !WAIT if_bit(P0.0) CALL !PW_CT if_bit(!CY) TO_CNT=#0 if(AX>=#12582) if(AX<#41942) SELMOD=#2 INTM0=#00000000B else CALL !S_M0SET endif else CALL !S_M0SET endif else CALL !S_M0SET endif endif endif RET $EJECT ;****************************** ;* Leader high detection ;****************************** LEAD_H: if_bit(!P0.0) CALL !WAIT if_bit(!P0.0) CALL !PW_CT if_bit(!CY) TO_CNT=#0 if(AX>=#7549) if(AX<#20971) if(AX>#12582) SELMOD=#3 WORKP=#0000H (WORKP)+2=#8000H else SELMOD=#4 INTM0=#00000100B endif else CALL !S_M0SET endif else CALL !S_M0SET endif else CALL !S_M0SET endif endif endif RET $EJECT 96
; Level check P0.0 = 1:noise ; 100-s wait ; Timer value read ; ; ; ; 3 ms 10 ms Leader high detection mode INTP0 falling edge
; Set to starting edge detection mode. ; Set to starting edge detection mode. ; Set to starting edge detection mode.
; Level check P0.0 = 0:noise ; 100-s wait ; Timer value read ; 1.8 ms ; 5 ms ; Custom/data code (3 ms)? ; Data read mode ; Initialize work area. ; Set the most significant bit to 1 (to verify the end of data). ; Repeat detection mode ; INTP0 rising ; Set to starting edge detection mode. ; Set to starting edge detection mode. ; Set to starting edge detection mode.
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
;******************************* ;* Custom/data code read ;******************************* CDCODE: if_bit(!P0.0) CALL !WAIT if_bit(!P0.0) CALL !PW_CT if_bit(!CY) TO_CNT=#0 if(AX>=#2096) if(AX<#10485) if(AX>=#7549) SET1 CY else CLR1 CY endif HL=#WORKP+3 C=#4 WKSHFT: A=[HL] RORC A,1 [HL]=A HL-DBNZ C,$WKSHFT if_bit(CY)
; Level check P0.0 = 1: noise ; 100-s wait ; Timer value read
; 0.5 ms ; 2.5 ms ; 1.8 ms
; Set work area address. ; Set the number of digits in the work area. ; 1-bit data save ; 1-bit shift
; End of shifting all digits
; End of 32-bit input? ; Custom code check if(WORKP+0==#CSTM) (A) A^=WORKP+1 if(A==#0FFH) ; Custom code inverse data check A=WORKP+2 ; Data code inverse data check A^=WORKP+3 if(A==#0FFH) ; Save input data. RMDATA=WORKP+2 (A) ; Set in the input data present state. SET1 IPDTFG CLR1 RMDTSET CLR1 RPT CLR1 RMDTOK CALL !S_M5SET else ; Set to starting edge detection mode. CALL !S_M0SET endif else ; Set to starting edge detection mode. CALL !S_M0SET endif else CALL !S_M0SET endif endif else CALL !S_M0SET ; Set to starting edge detection mode. endif else 97
78K/0 SERIES APPLICATION NOTE
CALL !S_M0SET endif else CALL !S_M0SET endif endif endif RET $EJECT ;****************************** ;* Repeat code detection ;****************************** REPCD: if_bit(P0.0) CALL !WAIT if_bit(P0.0) if_bit(RMDTOK) CALL !PW_CT if_bit(!CY) TO_CNT=#0 if(AX<=#4193) SET1 RPT CLR1 RMDTOK CLR1 RMDTSET CALL !S_M5SET else CALL !S_M0SET endif else CALL !S_M0SET endif else CALL !S_M0SET endif endif endif RET $EJECT
; Set to starting edge detection mode.
; Set to starting edge detection mode.
; Level check P0.0 = 1: noise ; 100-s wait ; Is the data valid? ; Timer value read
; 1 ms ; Input signal check at the end of data
; Set to starting edge detection mode.
; Set to starting edge detection mode.
; Set to starting edge detection mode.
98
CHAPTER 5 16-BIT TIMER/EVENT COUNTER APPLICATION
;********************************************* ;* Error data detection ;********************************************* ENDCHK: if_bit(!P0.0) ; Level check P0.0 = 1:noise CALL !WAIT ; 100-s wait if_bit(!P0.0) CLR1 IPDTFG ; Error data input CLR1 RPT ; Input signal invalid CALL !S_M0SET ; Set to starting edge detection mode. endif endif RET ;********************************************* ;* Calculation of capture register value ;********************************************* PW_CT: if_bit(OVF0) ; OVF0 after edge detection? if(CR01<#10000-33) (AX) ; Interrupt reception processing time = 65 clocks (MAX) CLR1 OVF0 SET1 OVSENS SET1 TO_FLG endif endif CR01_NP=CR01 (AX) A=CR01_NP+0 A-=CR01_OP X=A A=CR01_NP+1 SUBC A,CR01_OP+1 BC=AX if_bit(CY) if_bit(TO_FLG) CLR1 CY endif else if_bit(TO_FLG) SET1 CY endif endif CR01_OP=CR01_NP (AX) AX=BC CLR1 TO_FLG RET ; Capture register value read ; AX=CR01_NP-CR01_OP
; ; ; ;
Calculation result save CR01_NP>CR01_OP Timer overflow present (flag test). Normal data
; Timer overflow ; Error occurred.
; Calculation result restored.
99
78K/0 SERIES APPLICATION NOTE
;******************************************** ;* 100-s wait ;******************************************** WAIT: R=#(838-14-12-8)/12 ; CALL(14), RET(12), MOV(8) WAITCT: ; Set 100-s. DBNZ B,$WAITCT ; 1 instruction, 12 clocks RET ;******************************************** ;* Starting edge detection mode setting ;******************************************** S_M0SET: TO_CNT=#0 SELMOD=#0 ; Starting edge detection mode INTM0=#00000000B ; INTP0 falling edge RET ;******************************************** ;* Error data detection mode setting ;******************************************** S_M5SET: RPTCT=#16 ; Counter for 250-ms measurement SELMOD=#5 ; End of data input mode RMENDCT=#2 ; Counter to verify no input RET
100
CHAPTER 6 8-BIT TIMER/EVENT COUNTER APPLICATION
CHAPTER 6 8-BIT TIMER/EVENT COUNTER APPLICATION
The 8-bit timer/event counter in the 78K/0 Series has the three functions of interval timer, external event counter, and square-wave output. In addition, the 8-bit timer/event counter has two on-chip channels. Moreover, they can be used as a 16-bit timer/event counter by connecting them in cascade. The 8-bit timer/event counter requires the setting of the following five registers: * Timer clock selection register 1 (TCL1) * 8-bit timer mode control register (TMC1) * 8-bit timer output control register (TOC1) * Port mode register 3 (PM3) * Port 3 (P3)
101
78K/0 SERIES APPLICATION NOTE
Figure 6-1. Format of Timer Clock Selection Register 1
Symbol 7 6 5 4 3 2 1 0 Address FF41H At reset 00H R/W R/W
TCL1 TCL17 TCL16 TCL15 TCL14 TCL13 TCL12 TCL11 TCL10
Count clock selection of TCL13 TCL12 TCL11 TCL10 8-bit timer register 1 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 0 0 0 0 1 1 1 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 0 1 0 1 0 1 0 1 0 1 Falling edge at TI1 Rising edge at TI1 fX/2 (2.5 MHz) fX/22 (1.25 MHz) fX/23 (625 kHz) fX/24 (313 kHz) fX/25 (156 kHz) fX/26 (78.1 kHz) fX/27 (39.1 kHz) fX/28 (19.5 kHz) fX/29 (9.8 kHz) fX/210 (4.9 kHz) fX/212 (1.2 kHz) Setting prohibited
Other than the above
Count clock selection of TCL17 TCL16 TCL15 TCL14 8-bit timer register 2 0 0 0 0 0 1 0 0 1 1 1 0 0 0 0 1 1 1 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 0 1 0 1 0 1 0 1 0 1 Falling edge at TI2 Rising edge at TI2 fX/2 (2.5 MHz) fX/22 (1.25 MHz) fX/23 (625 kHz) fX/24 (313 kHz) fX/25 (156 kHz) fX/26 (78.1 kHz) fX/27 (39.1 kHz) fX/28 (19.5 kHz) fX/29 (9.8 kHz) fX/210 (4.9 kHz) fX/212 (1.2 kHz) Setting prohibited
Caution When TCL1 will be rewritten with data other than identical data, rewrite after temporarily stopping the timer. Remarks 1. fX : Main system clock oscillation frequency 2. TI1: Input pin of 8-bit timer register 1 3. TI2: Input pin of 8-bit timer register 2 4. The values in parentheses apply to operation with fX = 5.0 MHz.
1 1 1 1 1 1 1
Other than the above
102
CHAPTER 6 8-BIT TIMER/EVENT COUNTER APPLICATION
Figure 6-2. Format of the 8-Bit Timer Mode Control Register
Symbol TMC1
7 0
6 0
5 0
4 0
3 0
2
1
0
Address FF49H
At reset 00H
R/W R/W
TMC12 TCE2 TCE1
TCE1 0 1
Controlling the operation of 8-bit timer register 1 Stop operation (TM1 is cleared to 0) Operation enabled
TCE2 0 1
Controlling the operation of 8-bit timer register 2 Stop operation (TM2 is cleared to 0) Operation enabled
TMC12 Selection of the operating mode 8-bit timer register x 2-channel mode 0 (TM1, TM2) 1 16-bit timer register x 1-channel mode (TMS)
Cautions 1. Switch the operating mode after stopping timer operation. 2. When used as a 16-bit timer register, use TCE1 to enable or stop operation.
103
78K/0 SERIES APPLICATION NOTE
Figure 6-3. Format of the 8-Bit Timer Output Control Register
Symbol
7
6
5
4
3 LVS1
2
1
0
Address FF4FH
At reset 00H
R/W R/W
TOC1 LVS2
LVR2 TOC15 TOE2
LVR1 TOC11 TOE1
TOE1 Output control of 8-bit timer/event counter 1 0 1 Output prohibited (port mode) Output enabled
TOC11 Control of timer output flip-flop of 8-bit timer/event counter 1 0 1 Inversion disabled Inversion enabled
Setting the state of the timer output LVS1 0 0 1 1 LVR1 flip-flop of 8-bit timer/event counter 1 0 1 0 1 Do not change. Reset the timer output flip-flop (0) Set the timer output flip-flop (1) Setting prohibited
TOE2 Output control of 8-bit timer/event counter 2 0 1 Output prohibited (port mode) Output enabled
TOC15 Control of timer output flip-flop of 8-bit timer/event counter 2 0 1 Inversion disabled Inversion enabled
Setting the state of the timer output LVS2 0 0 1 1 LVR2 flip-flop of 8-bit timer/event counter 2 0 1 0 1 Do not change Reset the timer output flip-flop (0) Set the timer output flip-flop (1) Setting prohibited
Cautions 1. Always set TOC1 after stopping timer operation. 2. When LVS1, LVS2, LVR1, and LVR2 are read out after data were set, 0's are read out.
104
CHAPTER 6 8-BIT TIMER/EVENT COUNTER APPLICATION
Figure 6-4. Format of Port Mode Register 3
Symbol PM3 7 6 5 4 3 2 1 0 Address FF23H At reset FFH R/W R/W
PM37 PM36 PM35 PM34 PM33 PM32 PM31 PM30
PM3n Selection of the I/O mode of pin P3n (n=0 to 7) 0 1 Output mode (output buffer on) Input mode (output buffer off)
Caution When the P31/TO1 and P32/TO2 pins are used for timer output, do not only set the output latches of PM31 and PM32 to 0, also set the output latches of P31 and P32 to 0.
105
78K/0 SERIES APPLICATION NOTE
6.1 SETTING THE INTERVAL TIMER When the interval timer is used, the operating mode of the 8-bit timer is set by the 8-bit timer mode control register (TMC1) and the interval time is set by timer clock selection register 1 (TCL1). The values of the compare registers (CR10, CR20) are set based on the interval time and count clock. The setting time is determined in the form shown below. Setting-time = (value-in-compare-register + 1) x count-clock-period The setting time can be determined in a similar manner even when used as an 8-bit timer or as a 16bit timer. However, when used as a 16-bit timer, the count clock becomes the value selected in bits 0 to 3 (TCL10 to TCL13) in TCL1. Next, examples of each mode of the 8-bit timer and 16-bit timer are illustrated. Figure 6-5. Count Timing of an 8-Bit Timer
Count clock
TM1, TM2
N-2 N-1
N
00
01
02
N-2 N-1
N
INTTM1, INTTM2
TO1
106
CHAPTER 6 8-BIT TIMER/EVENT COUNTER APPLICATION
6.1.1 Setting an 8-Bit Timer This example describes using 8-bit timer 2 and setting the interval times of 500 s and 100 ms. (a) For the 500-s interval <1> TMC1 setting Select the "8-bit timer register x 2-channel" mode and enable "8-bit timer 2" operation. <2> TCL1 setting A setting above 500 s is possible. Select the highest possible resolution of f X/2 4. <3> CR20 setting 1 4.19 MHz/2 4 . N = 500 s x 4.19 MHz/24 - 1 = 130 . 500 s = (N + 1) x (1) Program listing TCL1 = #10001000B CR20 = #130 TMC1 = #00000010B ; Select fX/2 4 for the count clock.
107
78K/0 SERIES APPLICATION NOTE
(b) For the 100-ms interval <1> TMC1 setting Select the "8-bit timer register x 2-channel" mode and enable "8-bit timer 2" operation. <2> TCL1 setting A setting above 100 ms is possible. Select the highest possible resolution of fX /212 . <3> CR20 setting 1 4.19 MHz/212 . N = 100 ms x 4.19 MHz/212 - 1 = 101 . 100 ms = (N + 1) x (1) Program listing TCL1 = #11111111B CR20 = #101 TMC1 = #00000010B ; Select count clock fX /212 .
108
CHAPTER 6 8-BIT TIMER/EVENT COUNTER APPLICATION
6.1.2 Setting the 16-Bit Timer This example describes connecting 8-bit timer 1 and 8-bit timer 2 in a cascade and setting the interval times of 500 ms and 10 s. (a) For the 500-ms interval <1> TMC1 setting In the "16-bit timer register x 1-channel" mode, enable the operations of 8-bit timers 1 and 2. <2> TCL1 setting A setting above 500 ms is possible. Select the highest possible resolution of fX/2 5. <3> CR10 and CR20 settings N+1 500 ms = 4.19 MHz/2 5 . N = 500 ms x 4.19 MHz/25 - 1 = 65468 = FF6CH . CR10 = 6CH, CR20 = FFH (1) Program listing TCL1 CR10 CR20 TMC1 = = = = #00001001B #06CH #0FFH #00000111B
; Set 65468 in CR10 and CR20. ; CR10 = 6CH, CR20 = FFH
109
78K/0 SERIES APPLICATION NOTE
(b) For the 10-s interval <1> TMC1 setting In the "16-bit timer register x 1-channel" mode, enable the operations of 8-bit timers 1 and 2. <2> TCL1 setting A setting above 10 s is possible. Select the highest possible resolution of f X/210 . <3> CR10 and CR20 settings N+1 10 s = 4.19 MHz/210 . N = 10 s x 4.19 MHz/210 - 1 = 40959 = 9FFFH . CR10 = FFH, CR20 = 9FH (1) Program listing TCL1 CR10 CR20 TMC1 = = = = #00001110B #0FFH #9FH #00000111B
; Set 40959 in CR10 and CR20. ; CR10 = FFH, CR20 = 9FH
110
CHAPTER 6 8-BIT TIMER/EVENT COUNTER APPLICATION
6.2 MUSICAL SCALE GENERATION In this example, the square-wave output (P31/TO1) function of 8-bit timer/event counter 1 is used and a program is illustrated that supplies pulses to an externally attached buzzer to generate a musical scale. Figure 6-6. Musical Scale Generation Circuit
VDD
PD78044F
P31/TO1
The output frequency from pin P31/TO1 is set in the count clock and the compare register. In this example, because the center of the frequencies of the musical scale is set in the range of 523 Hz and 1046 Hz, f X/2 5 is selected for the count clock. Table 6-1 lists the settings of the musical scale, compare registers, and frequencies of the pulses to be output. However, because the timer output matches the compare register twice and is created in one period, the interval setting is in one-half of a period. Figure 6-7. Timer Output and Interval
Interval
CR10 matching interval
Timer output period
111
78K/0 SERIES APPLICATION NOTE
In the temporal length of the sound, the interval time is set in the 8-bit timer/event counter 2. The number of interrupts are counted and the output time is determined. In this example, 8-bit timer/event counter 2 is set to 20 ms. Table 6-1. Musical Scale and Frequencies
Musical scale C D E F G A B C Musical scale frequencies (Hz) 523.25 587.33 659.25 698.46 783.98 880.00 987.77 1046.5 Compare register value 124 111 98 93 83 73 65 62 Output frequency (Hz) 524.3 585.1 662.0 697.2 780.2 885.6 993.0 1040
The format of the data table in this program is shown below. TABLE: DB musical scale data 1, sound length data 1 DB musical scale data 2, sound length data 2
. . . . . .
DB musical scale data n, sound length data n DB 0, 0 When there is a rest, musical scale data is set to 0. At the end of data, the length of the sound data is set to 0. Example Count of the 8-bit timer/event counter 2 when the sound is output for one second Count = 1 s/20 ms = 50 (Data for the count is set to 50.) Data in this program illustrates an example where C, D, E, ..., C are each output in order for one second.
112
CHAPTER 6 8-BIT TIMER/EVENT COUNTER APPLICATION
(1) Package description MLDY: Subroutine name of the musical scale generation program Bank 0: A, B, HL
Name POINT LNG Use Save the pointer of table data. Count the length of the sound data. Attribute SADDR Byte 1
1 level, 3 bytes * 8-bit timer/event counters 1 and 2 * P31/TO1 * Subroutine MLDY is set. * Interrupts enabled * Call subroutine MLDY. (2) Use example EXTRN
. . .
MLDY !MLDY
CALL EI
113
78K/0 SERIES APPLICATION NOTE
(3) SPD chart
MLDY
Set P31/TO1 to the output mode. Set the pointer (POINT) to the reference table to 0. Set the length of the sound data (LNG) to the initial data of 1. 8-bit timer/event counter 1 is set to the output mode. 8-bit timer/event counter 2 is set to 20 ms. 8-bit timer 2 interrupt enabled.
INTTM2
Select register bank 0 Decrement the length of the sound data (LNG) IF : At the end of the output time THEN Look up sound data indicated by the pointer IF : Sound data No-sound data THEN Set sound data in the compare register of timer 1 ELSE Disable TO1 output of timer 1 Look up the length data of the sound IF : Length of sound data End of musical scale generation data THEN Set the length of sound data ELSE Timer 2 interrupt disabled Timer 2 operation stopped
114
CHAPTER 6 8-BIT TIMER/EVENT COUNTER APPLICATION
(4) Program listing PUBLIC CSEG DW ML_DAT DSEG POINT: DS LNG: DS VETM2 MLDY AT 18H INTTM2 SADDR 1 1
; Setting the vector address of 8-bit timer/event counter 2 ; Pointer to table data ; Length data of sound
;************************************************ ;* Musical scale generation initialization ;************************************************ ML_SEG CSEG MLDY: CLR1 PM3.1 ; Set bit 1 of port 3 in output mode. POINT=#0 ; Initial setting of the pointer LNG=#1 TOC1=#00000011B ; Set to the TO1 output mode. TCL1=#11011001B CR20=#163 ; Set timer 2 to 20 ms. TMC1=#00000010B ; Timer 2 operation enabled CLR1 TMMK2 ; Timer 2 interrupt enabled RET $EJECT
115
78K/0 SERIES APPLICATION NOTE
;***************************************** ;* Setting musical scale generation ;***************************************** TM2_SEG CSEG INTTM2: SEL RB0 LNG-if(LNG==#0) B=POINT (A) HL=#TABLE ; Setting the start address of the table A=[HL+B] if(A!=#0) CLR1 TCE1 ; Sound data setting CR10=A SET1 TOE1 SET1 TCE1 else CLR1 TOE1 endif B++ ; Increment pointer. A=[HL+B] ; Read the length data of the sound if(A!=#0) ; Is the sound being output? LNG=A ; Sound length data setting B++ POINT=B (A) else SET1 TMMK2 ; Timer 2 interrupt disabled CLR1 TCE2 ; Timer 2 operation stopped endif endif RETI ;***************************************** ;* Musical scale data table ;***************************************** TABLE: DB 124,50 ;C DB 111,50 ;D DB 98,50 ;E DB 93,50 ;F DB 83,50 ;G DB 73,50 ;A DB 65,50 ;B DB 62,50 ;C DB 00,00 ; End
116
CHAPTER 7 WATCH TIMER APPLICATION
CHAPTER 7 WATCH TIMER APPLICATION
The 78K/0 Series watch timer has a watch timer function that uses as the source signal the main system clock or the subsystem clock and overflows every 0.5 seconds, and an interval timer function capable of setting six types of basic times. These two functions can be used at the same time. The watch timer is set by timer clock selection register 2 (TCL2) and watch timer mode control register (TMC2). Figure 7-1. Format of Timer Clock Selection Register 2
Symbol 7 6 5 4 3 0 2 1 0 Address FF42H At reset 00H R/W R/W
TCL2 TCL27 TCL26 TCL25 TCL24
TCL22 TCL21 TCL20
TCL22 TCL21 TCL20 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1
Count clock selection Watchdog timer mode fX/23 (625 kHz) fX/24 (313 kHz) fX/25 (156 kHz) fX/26 (78.1 kHz) fX/27 (39.1 kHz) fX/28 (19.5 kHz) fX/29 (9.8 kHz) fX/211 (2.4 kHz) Interval timer mode fX/24 (313 kHz) fX/25 (156 kHz) fX/26 (78.1 kHz) fX/27 (39.1 kHz) fX/28 (19.5 kHz) fX/29 (9.8 kHz) fX/210 (4.9 kHz) fX/212 (1.2 kHz)
TCL24 Count clock selection for the watch timerNote 0 1 fX/28 (19.5 kHz) fXT (32.768 kHz)
TCL27 TCL26 TCL25 Selection of the buzzer output frequency 0 1 1 1 1 x 0 0 1 1 x 0 1 0 1 Buzzer output prohibited fX/210 (4.9 kHz) fX/211 (2.4 kHz) fX/212 (1.2 kHz) Setting prohibited
Note When a main system clock at 1.25 MHz or lower and an FIP controller/driver are used simultaneously, select fX/28 as the count clock for the watch timer. Caution When TCL2 will be rewritten with data other than identical data, rewrite after temporarily stopping timer operation.
117
78K/0 SERIES APPLICATION NOTE
Remarks 1. 2. 3. 4.
fX : Main system clock oscillation frequency fXT : Subsystem clock oscillation frequency x : Don't care The values in parentheses apply to operation with fX = 5.0 MHz or fXT = 32.768 kHz. Figure 7-2. Format of the Watch Timer Mode Control Register
Symbol TMC2
7 0
6
5
4
3
2
1
0
Address FF4AH
At reset 00H
R/W R/W
TMC26 TMC25 TMC24 TMC23 TMC22 TMC21 TMC20
TMC23 TMC20 Selection of the set time for the watch flag 0 1 0 1 1 0 214/fW (0.5 s) 213/fW (0.25 s) 25/fW (977 s) 24/fW (488 s)
TMC21 Control of prescaler operationNote 0 1 Clear after stopping operation Operation enabled
TMC22 Control operation of a 5-bit counter 0 1 Clear after stopping operation Operation enabled
Selection of the prescaler TMC26 TMC25 TMC24 interval time 0 0 0 0 1 1 0 0 1 1 0 0 0 1 0 1 0 1 24/fW (488 s) 25/fW (977 s) 26/fW (1.95 ms) 27/fW (3.91 ms) 28/fW (7.81 ms) 29/fW (15.6 ms) Setting prohibited
Other than the above
Caution When a watch timer is used, do not frequently clear the prescaler. Remarks 1. fW: Clock frequency of the watch timer (fX/28 or fXT) 2. The values in parentheses apply to operation with fW = 32.768 kHz.
118
CHAPTER 7 WATCH TIMER APPLICATION
7.1 WATCH AND LED DISPLAY PROGRAM An example using the watch timer is illustrated for a time count using the 0.5-second overflow and LED dynamic display using the 1.95-ms interval. When the time count tests the overflow flag each time a subroutine is called. When it is set, count up processing of seconds is performed. Because overflow is generated at 0.5 s, when there are 120 counts, 1 minute is counted. The overflow test is performed at 1.95-ms intervals in order not to lose data. The watch display of this program is a 24-hour display. Minute data and hour data are separately stored in memory as the high-order and low-order digits. Figure 7-3. Schematic of Watch Data
Seconds data 0-120
Minutes data Low order 0-9 High order 0-5
Hours data Low order 0-9 High order 0-2
119
78K/0 SERIES APPLICATION NOTE
An LED dynamic display is a four-digit display that switches the display digits in each 1.95-ms interval. In this example, the high-order four bits of P3 in the digit signal selects P12 where the LEDs in the segment signal can be driven directly. The LED display displays the digits shown in the display digit area (DIGCT) of the LED display area (LEDDP). Also, when the digit signal switches, switching is performed after the segment signal is turned off in order not to shift neighboring digit displays. Figure 7-4. LED Display Timing
P34 P35 P36 P37
Port 12 DIGCT 0 1 2 3 0 1 2 3 0 1 2 3
Segment signal off
Figure 7-5. Example Circuit of the Watch Timer
PD78044F
7-segment LED x 4 P120 P127 P37 P36 P35 P34
120
CHAPTER 7 WATCH TIMER APPLICATION
(1) Package description SECD : Area storing seconds data MINDP : Area storing minutes data HOURDP : Area storing hours data LEDDP : LED display area Bank 0: AX, B, HL
Name MINDP HOURDP SECD DIGCT LEDDP Minutes data storage Hours data storage Seconds data storage LED display digit data storage LED display data 4 1 Use Attribute SADDRP Byte 2
* Watch timer * P34-37 * P12 * Watch operation of 0.5 s, interval of 1.95 ms * Watch timer interrupt enabled
TMC2 = #00100110B TMMK3 = 0
Startup is by the interval timer interrupt request of the watch timer. (2) Use example EXTRN MINDP,HOURDP,SECD,LEDDP TMC2 = #00100110B CLR1 TMMK3 EI ; 0.5-s watch operation, 1.95-ms interval ; Watch timer interrupt enabled
121
78K/0 SERIES APPLICATION NOTE
(3) SPD chart
INTTM3
Select register bank 0 Time count TIME LEDs display LEDDSP
LEDDSP
Turn segment signal off IF : Digit counter (DIGCT) = 0 THEN Initial setting of the digit signal ELSE Shift the digit signal to the one bit in the high-order direction The segment signal that displays the digit counter is output Increment the digit counter
TIME
IF : The watch timer interrupt request flag is set THEN Increment seconds counter IF : Seconds counter=120 THEN Set the seconds counter to 0 Minutes (low order) counter increment IF : Minutes (low order) counter=10 THEN Set minutes (low order) counter to 0 Increment minutes (high order) counter IF : Minutes (high order) counter=6 THEN Set the minutes (high order) counter to 0 Increment hours (high order) counter IF : Time data 0204H THEN IF : Hours (low order) counter=10 THEN Set the hours (low order) counter to 0 Increment the hours (high order) counter ELSE Set the hours counter to 0
122
CHAPTER 7 WATCH TIMER APPLICATION
(4) Program listing PUBLIC WT_DATP MINDP: HOURDP: SECD: DIGCT: LEDDP: VETM3 DSEG DS DS DS DS DS CSEG DW HOURDP,MINDP,SECD,LEDDP SADDRP 2 2 1 1 4 AT 12H INTTM3
; ; ; ; ;
Area storing minutes data Area storing hours data Area storing seconds data LEDs display digit area LEDs display area
; Setting the vector address of the watch timer
;************************************** ;* Interval interrupt processing ;************************************** TM3_SEG CSEG INTTM3: SEL RB0 CALL !TIME CALL !LEDDPSP RETI
123
78K/0 SERIES APPLICATION NOTE
;******************** ;* LED display ;******************** LEDDPSP: P12=#0FFH DIGCT&=#00000011B if(DIGCT==#0) A=P3 A&=#00001111B A!=#00010000B P3=A else A=P3 A&=#11110000B X=A A=P3 A+=X P3=A endif B=DIGCT (A) HL=#LEDDP B=[HL+B] (A) HL=#SEGDT P12=[HL+B] (A) DIGCT++ RET SEGDT: DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB $EJECT 11000000B 11111001B 10100100B 10110000B 10011001B 10010010B 10000010B 11111000B 10000000B 10010000B 10001000B 10000011B 11000110B 10100001B 10000110B 10001110B
; Segment output off ; Adjustment of digit counter (0 to 3)
; Initial setting of digit signal (high-order 4 bits)
; Shift high-order 4 bits.
; ; ; ; ;
Address setting of display data Start address of the display area Display data setting Change to segment data. Segment signal output
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
0 1 2 3 4 5 6 7 8 9 A B C D E F
124
CHAPTER 7 WATCH TIMER APPLICATION
;*********************** ;* Watch count up ;*********************** TIME: if_bit(WTIF) CLR1 WTIF SECD++ if(SECD==#120) SECD=#0 (MINDP+0)++ if((MINDP+0)==#10) (MINDP+0)=#0 (MINDP+1)++ if(MINDP+1==#6) (MINDP+1)=#0 (HOURDP+0)++ if(HOURDP!=#0204H) (AX) if((HOURDP+0)==#10) (HOURDP+0)=#0 (HOURDP+1)++ endif else HOURDP=#0000H endif endif endif endif endif RET
; 0.5-s test ; 120 = 60 s/0.5
; Increment low-order part of minutes. ; Digit carry ; Increment high-order part of minutes. ; Digit carry
; Is hour data 24? ; Digit carry
125
78K/0 SERIES APPLICATION NOTE
[MEMO]
126
CHAPTER 8 SERIAL INTERFACE APPLICATION
CHAPTER 8
SERIAL INTERFACE APPLICATION
Table 8-1 lists the serial interfaces of the 78K/0 Series.
*
Table 8-1. Available Serial Interface Channels in Each Subseries
Serial interface configuration Channel 0 2-wire Channel 1 3-wire mode with automatic transmission/ reception function o x o x Channel 3 3-wire
3-wire
SBI
3-wire
Subseries PD78044F PD78044H PD780208 PD780228 o x o x o x o x o x o x o o o x
x x x o
Remark o: Function available x: Function not available The serial interface requires the setting of the following registers.
*
Serial interface Channel 0
Table 8-2. Serial Interface Registers
Registers to be used * * * * * * * * Timer clock selection register (TCL3) Serial operating mode register 0 (CSIM0) Serial bus interface control register (SBIC) Interrupt timing specification register (SINT) Timer clock selection register (TCL3) Serial operating mode register 1 (CSIM1) Automatic data transmit/receive control register (ADTC) Automatic data transmit/receive interval setting register (ADTI)
Channel 1
Remark This chapter describes only the register formats and sample applications for serial interface channels 0 and 1. For details of the register format for channel 3, refer to the PD780228 Subseries User's Manual (U12012E).
127
78K/0 SERIES APPLICATION NOTE
Figure 8-1. Format of Timer Clock Selection Register 3 (PD78044F and PD780208 Subseries)
Symbol 7 6 5 4 3 2 1 0 Address FF43H At reset 88H R/W R/W
TCL3 TCL37 TCL36 TCL35 TCL34 TCL33 TCL32 TCL31 TCL30
Selection of serial TCL33 TCL32 TCL31 TCL30 clock for serial interface channel 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 0 1 0 1 0 1 0 1 fX/22 (1.25 MHz) fX/23 (625 kHz) fX/24 (313 kHz) fX/25 (156 kHz) fX/26 (78.1 kHz) fX/27 (39.1 kHz) fX/28 (19.5 kHz) fX/29 (9.8 kHz) Setting prohibited
Other than the above
Selection of serial TCL37 TCL36 TCL35 TCL34 clock for serial interface channel 1 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 0 1 0 1 0 1 0 1 fX/22 (1.25 MHz) fX/23 (625 kHz) fX/24 (313 kHz) fX/25 (156 kHz) fX/26 (78.1 kHz) fX/27 (39.1 kHz) fX/28 (19.5 kHz) fX/29 (9.8 kHz) Setting prohibited
Other than the above
Caution When data other than the same data is rewritten into TCL3, rewrite after temporarily stopping timer operation. Remarks 1. fX: Main system clock oscillation frequency 2. The values in parentheses apply to operation with fX = 5.0 MHz.
128
CHAPTER 8 SERIAL INTERFACE APPLICATION
*
Figure 8-2. Format of Timer Clock Selection Register 3 (PD78044H Subseries)
Symbol
7
6
5
4
3 0
2 0
1 0
0 0
Address FF43H
At reset 88H
R/W R/WNote
TCL3 TCL37 TCL36 TCL35 TCL34
Selection of serial TCL37 TCL36 TCL35 TCL34 clock for serial interface channel 1 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 0 1 0 1 0 1 0 1 fX/22 (1.25 MHz) fX/23 (625 kHz) fX/24 (313 kHz) fX/25 (156 kHz) fX/26 (78.1 kHz) fX/27 (39.1 kHz) fX/28 (19.5 kHz) fX/29 (9.8 kHz) Setting prohibited
Other than the above
Note Bits 0 to 3 are read-only. When bits 0 to 3 are read, the operation will become unpredictable. Caution When data other than the same data is rewritten into TCL3, rewrite after temporarily stopping timer operation. Remarks 1. fX: Main system clock oscillation frequency 2. The values in parentheses apply to operation with fX = 5.0 MHz.
129
78K/0 SERIES APPLICATION NOTE
Figure 8-3. Format of Serial Operating Mode Register 0 (Only for the PD78044F and PD780208 Subseries) (1/2)
Symbol CSIM0 7 6 5 4 3 2 1 0 Address FF60H At reset 00H R/W R/WNote 1
CSIE CSIM CSIM CSIM CSIM CSIM COI WUP 0 04 03 02 01 00
R/W CSIM CSIM Clock selection for serial interface channel 0 01 00 0 1 1 x 0 1 Input clock from the outside to pin SCK0 Output of the 8-bit timer register 2 (TM2) Clock specified by bits 0 to 3 of the timer clock selection register 3 (TCL3)
R/W CSIM CSIM CSIM Operating PM25 P25 PM26 P26 PM27 P27 mode 04 03 02 0 x 0 1 1 0 0
Note 3 Note 3
First bit
SI0/SB0/P25 pin function SI0Note 2 (input) P25 (CMOS I/O)
SO0/SB1/P26 pin function SO0 (CMOS output) SB1 N-channel open drain I/O P26 (CMOS I/O)
SCK0/P27 pin function SCK0 (CMOS I/O) SCK0 (CMOS I/O)
1
x
0
0
0
1
3-wire serial MSB I/O mode LSB MSB
0
0
0
1
SBI mode
x 1 0
x 0
Note 3 Note 3
0
1
x 1 1 0
Note 3 Note 3
x 0 0 1 2-wire serial MSB I/O mode
SB0 N-channel open drain I/O P25 (CMOS I/O) SB0 N-channel open drain I/O
0
x 1 0
x 0
Note 3 Note 3
SB1 SCK0 N-channel N-channel open drain I/O open drain I/O P26 (CMOS I/O)
0
1
x
x
R/W WUP Wakeup function controlNote 4 0 1 An interrupt request signal is issued at each serial transfer in all of the modes. When the address received after the bus release in the SBI mode (when CMDD = RELD = 1) matches the data in the slave address register, an interrupt request signal is issued.
* *
Notes 1. 2. 3. 4.
Bit 6 (COI) is read-only. When only transmission is performed, this pin can be used as P25 (CMOS input). This pin can be used for a port function. When the wakeup function is used (WUP = 1), set bit 5 (SIC) of the interrupt timing specification register (SINT) to 0.
Caution The operating mode (3-wire serial I/O, 2-wire serial I/O, or SBI mode) must not be changed while serial interface channel 0 is enabled. To change the operating mode, temporarily stop serial operation beforehand. Remark x : Don't care PMxx : Port mode register Pxx : Port output latch
130
CHAPTER 8 SERIAL INTERFACE APPLICATION
Figure 8-3. Format of Serial Operating Mode Register 0 (Only for the PD78044F and PD780208 Subseries) (2/2)
R COI Slave address comparison result flagNote 0 1 Data in the slave address register and data in serial I/O shift register 0 do not match. Data in the slave address register and data in serial I/O shift register 0 match.
R/W CSIE0 Control of serial interface channel 0 operation 0 1 Stop operation Enable operation
Note When CSIE0 = 0, COI becomes 0.
*
Caution The operating mode (3-wire serial I/O, 2-wire serial I/O, or SBI mode) must not be changed while serial interface channel 0 is enabled. To change the operating mode, temporarily stop serial operation beforehand.
131
78K/0 SERIES APPLICATION NOTE
Figure 8-4. Format of the Serial Operating Mode Register 1 (PD78044F and PD780208 Subseries)
Symbol CSIM1 7 6 5 4 0 3 0 2 0 1 0 Address FF68H At reset 00H R/W R/W
CSIE DIR ATE 1
CSIM CSIM 11 10
CSIM CSIM Clock selection for serial interface channel 1 11 10 0 1 1 x 0 1 External clock inputNote 1 to SCK1 pin Output of 8-bit timer register 2 (TM2) Clock set by bits 4 to 7 of timer clock selection register 3 (TCL3)
ATE Selection of operating mode of serial interface channel 1 0 1 3-wire serial I/O mode 3-wire serial I/O mode with automatic transmit/receive function
DIR First bit 0 1 MSB LSB Control of serial clock counter operation Clear
SI1 pin function SI1/P20 (input)
SO1 pin function SO1 (CMOS output)
Shift register CSIE CSIM PM20 P20 PM21 P21 PM22 P22 1 operation 1 11 0 x
Note 2 Note 2 Note 2 Note 2 Note 2 Note 2
SI1/P20 pin function P20 (CMOS I/O)
SO1/P21 pin function P21 (CMOS I/O) SO1 (CMOS output)
SCK1/P22 pin function P22 (CMOS I/O) SCK1 (input) SCK1 (CMOS output)
Stop operation
x 1 0
x
x 0
x 0
x 1
x x Enable operation Count operation SI1
Note 3
Note 3 Note 3
1
x
(input)
1
0
1
*
Notes 1. When an external clock input is selected and CSIM11 is 0, set bits 2 and 1(STRB and BUSY1) of the automatic data transmit/receive control register (ADTC) to 0. 2. This can be used for a port function. 3. When only transmission is performed, this can be used as P20. Set bit 7 (RE) of ADTC to 0. Remark x : Don't care PMxx : Port mode register Pxx : Port output latch
132
CHAPTER 8 SERIAL INTERFACE APPLICATION
*
Figure 8-5.
Symbol CSIM1 7 6 5
Format of the Serial Operating Mode Register 1 (PD78044H Subseries)
4 0 3 0 2 0 1 0 Address FF68H At reset 00H R/W R/W
CSIE DIR 0Note 1 1
CSIM CSIM 11 10
CSIM CSIM Clock selection for serial interface channel 1 11 10 0 1 1 x 0 1 External clock input to SCK1 pin Output of 8-bit timer register 2 (TM2) Clock set by bits 4 to 7 of timer clock selection register 3 (TCL3)
DIR First bit 0 1 MSB LSB Control of serial clock counter operation Clear
SI1 pin function SI1/P20 (input)
SO1 pin function SO1 (CMOS output)
Shift register CSIE CSIM PM20 P20 PM21 P21 PM22 P22 1 operation 1 11 0 x
Note 2 Note 2 Note 2 Note 2 Note 2 Note 2
SI1/P20 pin function P20 (CMOS I/O)
SO1/P21 pin function P21 (CMOS I/O) SO1 (CMOS output)
SCK1/P22 pin function P22 (CMOS I/O) SCK1 (input) SCK1 (CMOS output)
Stop operation
x 1 0
x
x 0
x 0
x 1
x x Enable operation Count operation SI1
Note 3
Note 3 Note 3
1
x
(input)
1
0
1
Notes 1. Always set to 0. 2. This can be used for a port function. 3. When only transmission is performed, this can be used as P20 (CMOS I/O). Remark x : Don't care PMxx : Port mode register Pxx : Port output latch
133
78K/0 SERIES APPLICATION NOTE
Figure 8-6. Format of the Interrupt Timing Setting Register (Only for the PD78044F and D780208 Subseries)
Symbol SINT 7 0 6 CLD 5 SIC 4 SVAM 3 0 2 0 1 0 0 0 Address FF63H At reset 00H R/W R/WNote 1
R/W
SVAM SVA bits used as the slave address 0 1 Bits 0 to 7 Bits 1 to 7
R/W
SIC 0
Selection of the cause of the INTCSI0 interruptNote 2 Set CSIIF0 at the end of a transfer in serial interface channel 0.
1
Set CSIIF0 at the end of a transfer in serial interface channel 0 or when a bus release is detected.
R
CLD 0 1
Level of SCK0/P27 pinNote 3 Low level High level
Notes 1. Bit 6 (CLD) is read-only. 2. When the wakeup function is used, set SIC to 0. 3. When CSIE0 = 0, CLD becomes 0. Caution Always set bits 0 to 3 to 0. Remark SVA : Slave address register CSIIF0 : Interrupt request flag which corresponds to INTCSI0 CSIE0 : Bit 7 of serial operating mode register 0 (CSIM0)
134
CHAPTER 8 SERIAL INTERFACE APPLICATION
Figure 8-7.
Format of the Serial Bus Interface Control Register (Only for the PD78044F and PD780208 Subseries) (1/2)
6 5 4 3 2 1 0 Address FF61H At reset 00H R/W R/WNote
Symbol SBIC
7
BSYE ACKD ACKE ACKT CMDD RELD CMDT RELT
R/W
RELT
This is used to output the bus release signal. The SO latch is set (1) by RELT = 1. After setting the SO latch, this bit is automatically cleared (0). In addition, it is cleared (0) when CSIE0 = 0. This is used for command signal output. The SO latch is cleared (0) by CMDT = 1. After clearing the SO latch, this bit is automatically cleared (0). In addition, it is cleared (0) when CSIE0 = 0. Bus release detection Setting conditions (RELD = 1) * When a bus release signal (REL) is detected
R/W
CMDT
R
RELD
Clearing conditions (RELD = 0) * When a start transfer instruction is executed * When the values in SIO0 and SVA do not match while receiving an address * When CSIE0 = 0 * When RESET is input R CMDD Command detection
Clearing conditions (CMDD = 0) * * * * R/W When When When When a start transfer instruction is executed a bus release signal (REL) is detected CSIE0 = 0 RESET is input
Setting conditions (CMDD = 1) * When a command signal (CMD) is detected
ACKT
The acknowledge signal is output synchronized to the falling edge of the SCK0 clock immediately after the execution of the instruction that is set (1). After the output, this bit is automatically cleared (0). In addition, when starting the transfer in the serial interface and CSIE0 = 0, this bit is also cleared (0).
Note Bits 2, 3, and 6 (RELD, CMDD, ACKD) are read-only. Remark CSIE0: Bit 7 of serial operating mode register 0 (CSIM0)
135
78K/0 SERIES APPLICATION NOTE
Figure 8-7. Format of the Serial Bus Interface Control Register (Only for the PD78044F and PD780208 Subseries) (2/2)
R/W ACKE 0 1 Acknowledge signal output control Automatic output of the acknowledge signal is disabled. (Output by ACKT is possible.) Before the end of transfer The acknowledge signal is output synchronized to the falling edge of the ninth SCK0 clock (automatically output by ACKE = 1). The acknowledge signal is output synchronized to the falling edge of the SCK0 clock immediately after the execution of the instruction that is set (1) (automatically output by ACKE = 1). However, after the acknowledge signal is output, this is not automatically cleared (0).
After the transfer ends
R
ACKD
Acknowledge detection Setting conditions (ACKD = 1) * When the acknowledge signal (ACK) is detected at the rising edge of the SCK0 clock after the transfer ends
Clearing conditions (ACKD = 0) * When a falling edge of the SCK0 clock occurs immediately after the busy mode was released after executing a start transfer instruction * When CSIE0 = 0 * When RESET is input R/W BSYENote Control of synchronous busy signal output 0
The output of the busy signal is disabled synchronous to the falling edge of the SCK0 clock immediately after executing the instruction that is cleared (0). The busy signal is output starting at the falling edge of the SCK0 clock following the acknowledge signal.
1
Note The busy mode can be released at the start of transfer in the serial interface. However, the BSYE flag is not cleared to 0. Remark CSIE0 : Bit 7 of serial operating mode register 0 (CSIM0)
136
CHAPTER 8 SERIAL INTERFACE APPLICATION
Figure 8-8. Format of the Automatic Data Transmit/Receive Control Register (Only for the PD78044F and PD780208 Subseries)
Symbol ADTC 7 RE 6 5 4 ERR 3 TRF 2 1 0 Address FF69H At reset 00H R/W R/WNote 1
ARLD ERCE
STRB BUSY1 BUSY0
R/W
BUSY1 BUSY0 Busy input control 0 1 1 x 0 1 Busy input is not used. Busy input enabled (active high) Busy input enabled (active low)
R/W
STRB Strobe output control 0 1 Strobe output disabled Strobe output enabled
R
TRF 0
Status of the automatic transmit/receive functionNote 2 Detect the end of an automatic transmit/receive. (When interrupting automatic transmit/receive or when ARLD = 0, this bit becomes 0.) During automatic transmit/receive (By writing to SIO1, this becomes 1.) Error detection of the automatic transmit/receive function No error during automatic transmit/receive (By writing to SIO1, this bit becomes 0.) Error present during automatic transmit/receive
1
R ERR 0 1
R/W
ERCE 0 1
Control of the error checking of the automatic transmit/receive function Error checking disabled during automatic transmit/receive Error checking enabled during automatic transmit/receive (only when BUSY1 = 1) Selection of the operating mode of the automatic transmit/receive function Single-shot mode Repeat mode Receive control of the automatic transmit/receive function Reception disabled Reception enabled
R/W
ARLD 0 1
R/W RE 0 1
Notes 1. Bits 3 and 4 (TRF, ERR) are read-only. 2. Make the decision on the end of automatic transmit/receive based on TRF and not on CSIIF1 (interrupt request flag). (Continued on the next page) 137
78K/0 SERIES APPLICATION NOTE
Caution When bit 1 (CSIM11) of serial operating mode register 1 (CSIM1) is set to 0 and the external clock input is selected, set STRB and BUSY1 in ADTC to 0. Remark x: Don't care Figure 8-9. Format of the Automatic Data Transmit/Receive Interval Setting Register (Only for the PD78044F and PD780208 Subseries) (1/2)
Symbol 7 6 0 5 0 4 3 2 1 0 Address FF6BH At reset 00H R/W R/W
ADTI ADTI7
ADTI4 ADTI3 ADTI2 ADTI1 ADTI0
ADTI7 0 1
Control the interval time for data transfer No control of the interval time by ADTINote 1 Control of the interval time by ADTI (ADTI0 to ADTI4) Setting the interval time for data transfer (during fX = 5.0 MHz operation) Minimum valueNote 2 Maximum value Note 2 40.0 s + 1.5/fSCK 65.6 s + 1.5/fSCK 91.2 s + 1.5/fSCK 116.8 s + 1.5/fSCK 142.4 s + 1.5/fSCK 168.0 s + 1.5/fSCK 193.6 s + 1.5/fSCK 219.2 s + 1.5/fSCK 244.8 s + 1.5/fSCK 270.4 s + 1.5/fSCK 296.0 s + 1.5/fSCK 321.6 s + 1.5/fSCK 347.2 s + 1.5/fSCK 372.8 s + 1.5/fSCK 398.4 s + 1.5/fSCK 424.0 s + 1.5/fSCK
ADTI4 ADTI3 ADTI2 ADTI1 ADTI0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
36.8 s + 0.5/fSCK 62.4 s + 0.5/fSCK 88.0 s + 0.5/fSCK 113.6 s + 0.5/f SCK 139.2 s + 0.5/f SCK 164.8 s + 0.5/f SCK 190.4 s + 0.5/f SCK 216.0 s + 0.5/f SCK 241.6 s + 0.5/f SCK 267.2 s + 0.5/f SCK 292.8 s + 0.5/f SCK 318.4 s + 0.5/f SCK 344.0 s + 0.5/f SCK 369.6 s + 0.5/f SCK 395.2 s + 0.5/f SCK 420.8 s + 0.5/f SCK
(Continued on the next page)
138
CHAPTER 8 SERIAL INTERFACE APPLICATION
Notes 1. The interval time depends only on CPU processing. 2. Errors are contained in the interval time for data transfer. The minimum and maximum values of the interval time for each data transfer are determined from the following equations (n: values set in ADTI0 to ADTI4). However, when the minimum value calculated from the following equation is less than 2/fSCK , the minimum value of the interval time becomes 2/fSCK . 27 fX 27 fX 56 0.5 + fX fSCK 72 1.5 + fX fSCK
minimum value = (n + 1) x maximum value = (n + 1) x
+ +
*
Cautions 1. Do not write to ADTI during operation of the automatic transmit-receive function. 2. Always set bits 5 and 6 to 0. 3. When ADTI is being used to control the interval time for data transfer performed using the automatic transmission/reception function, busy control is disabled. Remarks 1. fX : Main system clock oscillation frequency 2. fSCK : Serial clock frequency
139
78K/0 SERIES APPLICATION NOTE
Figure 8-9. Format of the Automatic Data Transmit/Receive Interval Setting Register (Only for the PD78044F and PD780208 Subseries) (2/2)
Symbol 7 6 0 5 0 4 3 2 1 0 Address FF6BH At reset 00H R/W R/W
ADTI ADTI7
ADTI4 ADTI3 ADTI2 ADTI1 ADTI0
ADTI4 ADTI3 ADTI2 ADTI1 ADTI0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Setting the interval time for data transfer (during fX = 5.0 MHz operation) Minimum valueNote 446.4 s + 0.5/f SCK 472.0 s + 0.5/f SCK 497.6 s + 0.5/f SCK 523.2 s + 0.5/f SCK 548.8 s + 0.5/f SCK 574.4 s + 0.5/f SCK 600.0 s + 0.5/f SCK 625.6 s + 0.5/f SCK 651.2 s + 0.5/f SCK 676.8 s + 0.5/f SCK 702.4 s + 0.5/f SCK 728.0 s + 0.5/f SCK 753.6 s + 0.5/f SCK 779.2 s + 0.5/f SCK 804.8 s + 0.5/f SCK 830.4 s + 0.5/f SCK Maximum valueNote 449.6 s + 1.5/fSCK 475.2 s + 1.5/fSCK 500.8 s + 1.5/fSCK 526.4 s + 1.5/fSCK 552.0 s + 1.5/fSCK 577.6 s + 1.5/fSCK 603.2 s + 1.5/fSCK 628.8 s + 1.5/fSCK 654.4 s + 1.5/fSCK 680.0 s + 1.5/fSCK 705.6 s + 1.5/fSCK 731.2 s + 1.5/fSCK 756.8 s + 1.5/fSCK 782.4 s + 1.5/fSCK 808.0 s + 1.5/fSCK 833.6 s + 1.5/fSCK
Note Errors are contained in the interval time for data transfer. The minimum and maximum values of the interval time for each data transfer are determined from the following equations (n: values set in ADTI0 to ADTI4). However, when the minimum value calculated from the following equation is less than 2/f SCK, the minimum value of the interval time becomes 2/fSCK. 27 fX 27 fX 56 + fX 72 + fX 0.5 fSCK 1.5 fSCK
minimum value = (n + 1) x maximum value = (n + 1) x
+ +
*
Cautions 1. Do not write to ADTI during operation of the automatic transmit/receive function. 2. Always set bits 5 and 6 to 0. 3. When ADTI is being used to control the interval time for data transfer performed using the automatic transmission/reception function, busy control is disabled. Remarks 1. fX : Main system clock oscillation frequency 2. fSCK : Serial clock frequency
140
CHAPTER 8 SERIAL INTERFACE APPLICATION
8.1 INTERFACING WITH EEPROMTM (PD6252) The PD6252Note is a 2048-bit electrically programmable and erasable ROM (EEPROM). Writing to and reading from the PD6252 is performed through a 3-wire serial interface.
*
Note The PD6252 is provided for maintenance purposes only. Figure 8-10. PD6252 Pin Configuration
CE IC IC GND
1 2 3 4
8 7 6 5
VDD CS SCL SDA
141
78K/0 SERIES APPLICATION NOTE
Table 8-3. Description of PD6252 Pins
Pin number 1 Pin name CE I/O CMOS input Set high during data transfer. Caution Do not switch to this pin from high to low during data transfer. When this pin is switched from high to low, operate in the state where the CS pin (pin 7) is set low. When pins CE and CS are both set to low levels, the standby state is entered. In the standby state, low power consumption results. 2 3 4 5 IC Set the IC pin to a high or low level individually using an external resistor. Function
GND SDA
CMOS input/ N-channel opendrain output
Ground This pin is for data I/O. Attach a pull-up resistor externally for the N-channel open-drain I/O. SDA
6 7
SCL CS
CMOS input CMOS input
This is the clock input pin for data transfer. This is the chip select pin. The PD6252 can be operated by a high input. The read and write operations of a memory cell are not possible when at the low level. In the state where the SCL pin is high, this pin changes from low to high and the signal for starting operation of the serial bus interface results. In addition, when this pin changes from high to low, the signal of the end of operation of the serial bus interface results. Positive voltage (+5 V 10%)
8
VDD
-
142
CHAPTER 8 SERIAL INTERFACE APPLICATION
8.1.1 Communication in the 2-Wire Serial I/O Mode The 3-wire system in the PD6252 Note indicates the three wires of the serial clock (SCL), data (SDA), and chip select (CS). Consequently, except for handshakes, because the required wires in an interface become the two clock and data wires, when the 78K/0 Series is used to establish an interface, the 2-wire serial I/O mode is selected. An example using the PD78044F subseries is explained here.
*
Note The PD6252 is provided for maintenance purposes only. Figure 8-11. PD6252 Connection Example
PD78044F
VDD
PD6252
VDD
SCK0
SCL
CE
SB1
SDA
P32
CS
Table 8-4 and Figure 8-12 show the commands and communication formats when the PD6252 is read and written.
143
78K/0 SERIES APPLICATION NOTE
Table 8-4. PD6252 Command List
Command name RANDOM WRITE Command 00000000B [00H] MSB C7-C 0 Operation description After setting the word address (WA) (8 bits), write data is transferred. The write data are consecutive and a maximum of three bytes can be set. Correspondence of the word addresses WA : first data byte WA+1: second data byte WA+2: third data byte The write operation is executed during an internal write cycle after timing in which the CS pin falls from high to low. The memory contents, that are specified in the word address (WA) (current address) when the command was set, are sent to the read data buffer. When data is read from the SDA pin, the word address (WA) is incremented for every 8 bits read out and the corresponding memory contents are sent to the read data buffer. After setting the word address (WA), a data read is executed with the set word address (WA) as the first address. The difference from CURRENT READ is the word address (WA) is set after the command is executed. After setting the word address (WA), the operation is identical to CURRENT READ.
CURRENT READ
10000000B [80H] MSB C7-C 0 11000000B [C0H] MSB C7-C 0
RANDOM READ
144
Figure 8-12. PD6252 Communication Format (1/2)
(1) RANDOM WRITE
WA input Command input Write data input (WA) WB flag output Byte 1 WA7 WA6 WA5 WA4 WA3 WA2 WA1 WA0 D7 D6 D5 D4 D3 D2 D1 D0 Byte 2 0 0 0 0 0 0 0 0 (WA+1) (WA+2) Byte 3
CS
SDA
C7 C6 C5 C4 C3 C2 C1 C0
SCL CURRENT ADDRESS IN OUT IN WA WA+1 to WA+3
Internal WA
SDA mode
Operation starts when the CS pin rises from the low to high level in the state where the SCL pin is high. (STA issued)
WA holds the input value until STP is detected and then is incremented when one byte is written during the internal write cycle after STP arrives. WB flag is held for 8 clock inputs The first data byte is written to the memory at the SCL pin. specified in WA.
(2) CURRENT READ
A write is executed when the CS pin moves from the high to low level in the state where the SCL pin is high. WA becomes and holds the final write address + 1. (current address) (STP issued)
Current address Command input WB flag output 1 0 0 0 0 0 0 0 Read data (WA) (WA+1) D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 (WA+2) D0 D7 D6 (WA+n) D2 D1 D0
CS
SDA
C7 C6 C5 C4 C3 C2 C1 C0
SCL WA+2 WA+n Operation ends when the CS pin goes from the high to low level in the state where the SCL pin is high. WA becomes and holds the "final read address + 1" value. (current address) (STP issued) WA+n+1
Internal WA SDA mode IN
CURRENT ADDRESS = WA OUT
WA+1 OUT
CHAPTER 8 SERIAL INTERFACE APPLICATION
145
146 Figure 8-12. PD6252 Communication Format (2/2)
WA input (WA) C7 C6 C5 C4 C3 C2 C1 C0 1 1 0 0 0 0 0 0 WB flag output WA7 WA6 WA5 WA4 WA3 WA2 WA1 WA0 D7 D6 D5 D4 D3 D2 D1 D0 D7 (WA+1) ... (WA+n) D1 D0 CURRENT ADDRESS IN The WB flag is held while eight clocks are input to the SCL pin. The first byte of data read is the content of WA. The contents of WA+1,..., WA+n are read out sequentially by reading out each byte. Operation ends when the CS pin falls from the high to low level in the state where the SCL pin is high. (STP issued) WA becomes and holds the "final read address+1" value. OUT IN WA OUT WA+1 WA+n WA+n+1
(3) RANDOM READ
CS
SDA
78K/0 SERIES APPLICATION NOTE
SCL
Internal WA SDA mode
Operation starts when the CS pin rises from the low to high level in the state where the SCL pin is high. (STA issued)
CHAPTER 8 SERIAL INTERFACE APPLICATION
A program for the PD6252 is illustrated in <1> to <5>. In this example, the number of data bytes in one write or read in the interface is fixed at one byte. In addition, when the PD6252 is write busy (WB) while interfacing, the busy flag is set. <1> The CS pin (P32) is set to the high level to initiate the interface. <2> The write and read commands are transmitted. <3> WRITE BUSY data is received. If in the state where interfacing with the PD6252 is possible, 00H is received. When data other than 00H is received, the WRITE BUSY state is judged and processing to stop communication is performed. <4> Data for the command is transferred. <5> The CS pin (P32) is set low to end communication. (1) Package description T3_6252 : Name of PD6252 transfer subroutine RWRITE : RANDOM WRITE command value RREAD : RANDOM READ command value CREAD : CURRENT READ command value WADAT : Word address storage area TRNDAT : Transmission data storage area RCVDAT : Receive data storage area CMDDAT : Command data storage area BUSYFG : Busy state test flag CS6252 : CS pin (P32) of PD6252 A
Name WAADR TRNDAT RCVDAT CMDDAT Use Stores the word address (before the transfer begins) Stores the transmission data (before the transfer begins) Stores the receive data (after the transfer ends) Stores the command data (before the transfer begins) Attributes SADDR Bytes 1

Name BUSYFG WRITE BUSY state setting Use
147
78K/0 SERIES APPLICATION NOTE
1 level, 3 bytes * Serial interface channel 0 * P32 * Serial interface channel 0 settings 2-wire serial I/O mode, SB1 pin selection * Serial clock f X/2 4 * SB1 latch is the high level
CSIM0=#10011011B TCL3=#xxxx1000B RELT=1
Set the required data corresponding to command and T3_6252 is called. After returning from a subroutine, the busy flag (BUSYFG) is tested. When the busy flag is set, the transfer must be repeated because no transfer was performed. When in the receiving mode, after returning from a subroutine, the receive data is stored in RCVDAT.
148
CHAPTER 8 SERIAL INTERFACE APPLICATION
(2) Use example
Set each data in memory. UNTIL : No WRITE BUSY is present Clear the busy flag. Call T3_6252. Read in the receive data.
EXTRN EXTRN EXTBIT
RWRITE,RREAD,CREAD WADAT,TRNDAT,RCVDAT,CMDDAT,T3_6252 BUSYFG,CS6252 ; 2-wire serial I/O mode and SB1 pin settings ; Set SCK0 = 262 kHz. ; Set the CS pin on the PD6252 to the low level.
CSIM0=#10011011B TCL3=#10011000B CLR1 SB0 CLR1 CS6252 CLR1 PM3.2 CMDDAT=A : : WADAT=A : : TRNDAT=A : : repeat CLR1 BUSYFG CALL !T3_6252 until_bit(!BUSYFG) : : A=RCVDAT
149
78K/0 SERIES APPLICATION NOTE
(3) SPD chart
T3_6252
Clear the busy flag. Issue the start bit. Transmit command. WHILE : Waiting for the end of transfer (CSIIF0 = 0) Busy signal received WHILE : Waiting for the end of transfer (CSIIF0 = 0) IF : Not in the WB state (SIO0 = 00H) THEN CASE : CMDDAT OF : RWRITE Transfer the word address. WHILE : Waiting for the end of transfer Transmit data. WHILE : Waiting for the end of transfer BREAK OF : RREAD Transfer the word address. WHILE : Waiting for the end of transfer OF : CREAD Receive data. WHILE : Waiting for the end of transfer Save the receive data in memory. ELSE Set in busy state. Set BUSYFG. Issue stop bit.
150
CHAPTER 8 SERIAL INTERFACE APPLICATION
(4) Program listing PUBLIC PUBLIC PUBLIC DSEG DS DS DS DS RWRITE,RREAD,CREAD WADAT,TRNDAT,RCVDAT,CMDDAT,T3_6252 BUSYFG,CS6252 SADDR 1 ; Word address storage area 1 ; Transmission data storage area 1 ; Receive data storage area 1 ; Command data storage area
CSI_DAT WADAT: TRNDAT: RCVDAT: CMDDAT:
CSI_FLG BSEG BUSYFG DBIT RWRITE RREAD CREAD CS6252 EQU EQU EQU EQU 00H 0C0H 080H 0FF03H.2
; Busy state setting ; ; ; ; RANDOM WRITE mode RANDOM READ mode CURRENT READ mode 0FF03H=PORT3
CSI_SEG CSEG ;************************************** ;* PD6252 (3-wire) communication ;************************************** T3_6252: CLR1 BUSYFG SET1 CS6252 SIO0=CMDDAT (A) while_bit(!CSIIF0) endw CLR1 CSIIF0 SIO0=#0FFH while_bit(!CSIIF0) endw CLR1 CSIIF0 if(SIO0==#00H) switch (CMDDAT) case RWRITE: SIO0=WADAT (A) while_bit(!CSIIF0) endw CLR1 CSIIF0 SIO0=TRNDAT (A) while_bit(!CSIIF0) endw CLR1 CSIIF0 break case RREAD: SIO0=WADAT (A) while_bit(!CSIIF0) endw CLR1 CSIIF0
; Issue the start bit. ; Transfer the command. ; Wait for the end of transfer.
; Start reception of the busy signal. ; Wait for the end of transfer.
; Busy check
; Transfer the word address. ; Wait for the end of transfer.
; Start the data transfer. ; Wait for the end of transfer.
; Transfer the word address. ; Wait for the end of transfer.
151
78K/0 SERIES APPLICATION NOTE
case CREAD: SIO0=#0FFH while_bit(!CSIIF0) endw CLR1 CSIIF0 RCVDAT=SIO0 (A) ends else SET1 BUSYFG endif CLR1 CS6252 RET
; Start data reception. ; Wait for the end of transfer.
; Store the receive data.
; Set in the busy state
152
CHAPTER 8 SERIAL INTERFACE APPLICATION
8.2 INTERFACING WITH THE OSD LSI (PD6451A) The PD6451A, an OSD (On-Screen Display) LSI, displays VCR programming information or TV channels on a display by using it in conjunction with a microcontroller. To interface with the PD6451A, the four lines of DATA, CLK, STB, and BUSY are used. An example using the PD78044F subseries is described here. Figure 8-13. Connection Example with PD6451A
PD78044F
SCK1 SO1 STB BUSY
PD6451A
CLK DATA STB BUSY RGB
Display
RGB
Figure 8-14. PD6451A Communication Format
SCK1
SO1
DO7 DO6 DO5 DO4 DO3 DO2 DO1 DO0
STB
BUSY
The output of the strobe signal (STB) and testing the busy signal (BUSY) used in handshaking for interfacing to the PD6451A are automatically performed in serial interface channel 1 of the 78K/0 Series. To match the PD6451A's communication format, the strobe signal output enable and busy signal input enable (active high) mode is selected. Data (maximum of 32 bytes) to be transmitted to the buffer RAM area (FAC0H-FADFH) are automatically transmitted when the number of data bytes to be transmitted is set at the automatic data transmit/receive address pointer (ADTP) and multiple bytes of data are consecutive.
153
78K/0 SERIES APPLICATION NOTE
(1) Package description TR6451 : Name of PD6451A transfer subroutine DTVAL : Area for setting the number of transmission data bytes A
Name DTVAL Use Stores the number of bytes of transmission data Attributes SADDR Bytes 1
1 level, 2 bytes * Serial interface channel 1 * Serial interface channel 1 settings Automatic transmit/receive operation enabled, MSB first Busy input enabled (active high), strobe output enabled, single shot mode * Interval time for data transfer * Serial clock f X/2 4 * Set the P22 output latch to the high level. * P21, P22, P23 set in output mode, P24 in input mode
CSIM1=#10100011B ADTC=#00000110B ADTI=#00000000B TCL3=#1000xxxxB PM2=#xxx1000xB
When data will be transmitted to the buffer RAM (transmission from a high order address), the number of data bytes to be transmitted is set in DTVAL and TR6451 is called. When the data transfer ends, bit 3 (TRF) of the automatic data transmit/receive control register (ADTC) can be tested for verification.
154
CHAPTER 8 SERIAL INTERFACE APPLICATION
(2) Use example
Set data in the buffer RAM. Set the number of transmission data bytes in DTVAL. Call TR6451. WHILE : Waiting for the transfer to end
EXTRN SCK1 EQU
TR6451, DTVAL
P2.2 : : P2=#00000100B PM2=#11110001B CSIM1=#10100011B TCL3=#10001000B ADTC=#00000110B ADTI=#00000000B : : DE=#TABLE1 HL=#0FAC0H B=32 while(B>#0) B-[HL+B]=[DE] (A) DE++ endw DATVAL=#32 CALL !TR6451 while_bit(TRF) endw
; Set to the automatic transmit/receive function. ; SCK1 = 262 kHz ; The strobe and busy signals are present.
; Table reference address setting for transmission data ; Start address setting of the buffer RAM ; Number of transmission data bytes setting ; Transfer transmission data to the buffer RAM.
; Number of transmission data bytes setting ; Wait for the transfer to end.
155
78K/0 SERIES APPLICATION NOTE
TABLE1: DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB 11111111B 01000000B 11000000B 10000000B 11111100B 11101001B 10001100B 11011011B 10010101B 10100000B 07H 08H 1BH 6DH 00H 10H 11H 20H 20H 1CH 19H 13H 11H 24H 19H 00H 1EH 10H 1EH 00H 24H 15H ; ; ; ; ; ; Power-on-reset command 1 Vertical address 0 Horizontal address 0 Character size Command 0 LC send ON, blinking OFF, display ON
; Blinking ON, character: RED ; Color setting, background color: CYAN ; Display line 5 ; Display digit 0 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 7 8 K / 0 A P P L I C A T I O N N O T E
Remark For information on the commands and data in the output table data, refer to the PD6451A Data Sheet (Document No. IC-2337A).
156
CHAPTER 8 SERIAL INTERFACE APPLICATION
(3) SPD chart
TR6451
Set (number-of-data-bytes-transferred - 1) in ADTP. Set in the state before transfer. Start the transfer.
(4) Program listing PUBLIC CSI_DAT DSEG DTVAL: DS TR6451,DTVAL SADDR 1
; Number of data bytes setting area
CSI_SEG CSEG ;******************************* ;* PD6451A communication ;******************************* TR6451: A=DTVAL A-ADTP=A SIO1=#0FFH RET
; Number of data bytes setting
; Start the transfer.
157
78K/0 SERIES APPLICATION NOTE
8.3 SBI MODE INTERFACE The 78K/0 Series has the SBI mode which conforms to the NEC serial bus format. The SBI mode allows one master CPU to communicate with multiple slave CPUs via the two wires of clock and data. An example using the PD78044F subseries is explained here. Figure 8-15 shows a connection example and Figure 8-16 shows the communication format when using the SBI mode. Figure 8-15. Connection Example of the SBI Mode
VDD
PD78044F master
SB0 SCK0
PD78044F slave
SB0 SCK0
Slave CPU
SB SCK
Slave CPU
SB SCK
158
CHAPTER 8 SERIAL INTERFACE APPLICATION
Figure 8-16. SBI Mode Communication Format (a) Address transmission
SCK0 SB0 RELD set CMDD set A7 A6 A5 A4 A3 A2 A1 A0
(b) Command transmission
SCK0 SB0 CMDD set C7 C6 C5 C4 C3 C2 C1 C0
(c) Data transmission and reception
SCK0 SB0 D7 D6 D5 D4 D3 D2 D1 D0 ACK ACKD set
Table 8-5. SBI Mode Signal List
Signal name Address Command Data Clock ACK BUSY Output side Master Master Master/slave Master Receiving Slave sideNote Slave device selection Instruction to a slave device Data processed by a slave or master Transmit/receive synchronization signal for serial data Reception response signal State where communication is not possible Meaning
Note During normal operation, the receiving side outputs this signal, but when an error occurs that results in time out processing, the master CPU outputs this signal.
159
78K/0 SERIES APPLICATION NOTE
8.3.1 Application as a Master CPU The processing in (a) to (d) is performed for the slave CPU. (a) (b) (c) (d) Address transmission Command transmission Data transmission Data reception
Error checks <1> and <2> are performed in the communication in (a) to (d). <1> Time out processing During a master CPU transmission, when the ACK signal is not returned within a constant time (here, within the time it takes for the watch timer to generate five interrupt requests), an error is judged. The master CPU outputs the ACK signal and processing ends. Figure 8-17. Timed Out ACK Signal
End of transfer Master output
SB0
ACK (Time out) INTTM3 (ACKD test)
<2> Bus line test The master CPU tests whether the data was correctly output to the bus line by setting the transmission data in serial I/O shift register 0 (SIO0) and slave address register (SVA). Because bus line data is received by SIO0, the normal output of data is verified by testing bit 6 (COI) of serial operating mode register 0 (CSIM0) (set when SIO0 and SVA match) at the end of transfer. Figure 8-18. Bus Line Test
SIO0 = 0FH
0
0
0
0
1
1
1
1
SB0 = 07H
0
0
0
0
0
1
1
1
In Figure 8-18, because the values at the end of transfer do not match (SIO0 = 07H, SVA = 0FH), COI = 0 results and an error is generated in the bus line.
160
CHAPTER 8 SERIAL INTERFACE APPLICATION
(1) Package description M_TRANS : Name of master SBI transfer subroutine TR_MODE: Storage area of the selection of the transfer mode TRNDAT : Transmission data storage area RCVDAT : Receive data storage area TRADR : Selection of the address transmission mode TRCMD : Selection of command transmission mode TRDAT : Selection of data transmission mode RCDAT : Selection of data reception mode ERRORF : Error state test flag Subroutine A
Name TR_MODE ACKCT TRNDAT RCVDAT Use Stores the selection of the transfer mode Time out counter Stores the transmission data Stores the receive data Attributes SADDR Bytes 1

Name RCVFLG BUSYFG ERRORF ACKWFG Reception mode setting Busy state setting Error state setting ACK signal wait state setting Use
2 levels, 5 bytes * Serial interface channel 0 * Watch timer
161
78K/0 SERIES APPLICATION NOTE
* Serial interface channel 0 settings SBI mode, SB1 pin selection * Serial clock f X/2 4 * Set SO0 latch high. * Set the P27 output latch to the high level. * 1.95-ms interval for the watch timer * Watch timer interrupt enabled
CSIM0=#10010011B TCL3=#xxxx1000B RELT = 1 P27=1 TMC2=#00100110B
The data required for the transfer mode is set and M_TRANS is called. After returning from the subroutine, by testing the error flag (ERRORF), the presence of a transfer error can be determined. In addition, during the receiving mode, after returning from the subroutine, the reception data is saved in RCVDAT.
162
CHAPTER 8 SERIAL INTERFACE APPLICATION
(2) Use example
Transfer mode setting Transmission data setting Call M_TRANS. IF : Error occurs. Error processing
EXTRN EXTRN EXTBIT SCK0 SB1 : :
M_TRANS,TR_MODE,TRADR,TRCMD,TRDAT,RCDAT TRNDAT,RCVDAT ERRORF EQU EQU P2.7 P2.5
SET1 SB1 CSIM0=#10010111B TCL3=#10001000B TMC2=#00100110B CLR1 BSYE SET1 RELT SET1 SCK0 CLR1 SB1 CLR1 CSIMK0 CLR1 TMMK3 EI : : TR_MODE=#TRADR TRNDAT=#5AH CALL !M_TRANS if_bit(ERRORF) Error processing endif
; ; ; ; ;
Operate in the SBI mode. SCK0 = 262 kHz Set a 1.95-ms interval for the watch timer. Disable the busy signal output. Set the output latch.
; Enable serial interface channel 0 interrupt. ; Enable watch timer interrupt. ; Enable master interrupt.
163
78K/0 SERIES APPLICATION NOTE
(3) SPD chart
M_TRANS
CASE : TR_MODE OF : TRADR WHILE : SB0 = LOW WHILE : SCK0 = LOW Output command signal. Output bus release signal. OF : TRCMD WHILE : SB0 = LOW WHILE : SCK0 = LOW Output command signal. OF : TRDAT Set in the transmission mode. Clear RCVFLG. BREAK OF : RCDAT Set in the reception mode. Set RCVFLG. Set the output off data (FFH) of the bus line. BREAK Set to the transfer state. Set BUSYFG. Set transmission data in SIO0 and SVA. WHILE : Busy transferring (set BUSYFG) Save SIO0 data in RCVDAT. IF : transmission mode THEN IF : Error generated in the bus line THEN Set the error state. Set ERRORF.
164
CHAPTER 8 SERIAL INTERFACE APPLICATION
INTCSI0
Select register bank 0 IF : Transmission mode THEN IF : No ACK signal reception THEN Set the ACK waiting state. Set ACKWFG ELSE Release the busy state. Clear BUSYFG Release the error state. ELSE Clear ERRORF Output ACK signal Clear BUSYFG, ERRORF
INTTM3
Select register bank 0 IF : ACK waiting state THEN IF : ACK signal has been received. THEN Release the ACK waiting state. Clear ACKWFG Release the busy state. Clear BUSYFG ELSE IF : Time out THEN Process the time out error Release the ACK waiting state Clear ACKWFG Release the busy state Clear BUSYFG
165
78K/0 SERIES APPLICATION NOTE
(4) Program listing PUBLIC M_TRANS,TR_MODE,TRADR,TRCMD,TRDAT,RCDAT PUBLIC TRANDAT,RCVDAT,ERRORF VECSI0 VETM3 CSEG DW CSEG DW DSEG DS DS DS DS BSEG DBIT DBIT DBIT DBIT EQU EQU EQU EQU EQU EQU P2.5 P2.7 1 2 3 4 ; ; ; ; Address transmission mode selection Command transmission mode selection Data transmission mode selection Data reception mode selection AT 0EH INTCSI0 AT 12H INTTM3 SADDR 1 1 1 1
; Vector address setting of serial interface channel 0 ; Vector address setting of the watch timer
SBI_DAT TRNDAT: RCVDAT: TR_MODE: ACKCT: SBI_FLG RCVFLG BUSYFG ERRORF ACKWFG SB0 SCK0 TRADR TRCMD TRDAT RCDAT
; ; ; ;
Transmission data Reception data Transfer mode setting ACK time out count
; ; ; ;
Reception mode setting Busy transferring state Error display ACK wait state
166
CHAPTER 8 SERIAL INTERFACE APPLICATION
;************************************* ;* SBI data transfer processing ;************************************* SBI_SEG CSEG M_TRANS: switch(TR_MODE) case TRADR: SET1 PM2.5 while_bit(!SB0) CLR1 PM2.5 endw while_bit(!SCK0) endw SET1 CMDT NOP SET1 RELT A=#TRCMD case TRCMD: SET1 PM2.5 while_bit(!SB0) CLR1 PM2.5 endw while_bit(!SCK0) endw SET1 CMDT A=#TRDAT case TRDAT: CLR1 RCVFLG A=TRNDAT break case RCDAT: SET1 RCVFLG MOV A,#0FFH break ends SET1 SVA=A SIO0=A BUSYFG
; SB0 = HIGH?
; SCK = HIGH? ; Command signal output ; Wait ; Bus release signal output
; SB0 = HIGH?
; SCK = HIGH? ; Command signal output
; Set in the transmission mode. ; Transmission data setting
; Set in the reception mode. ; Reception buffer off
; Set in the busy transferring state. ; For use in bus line testing ; Start transfer. ; Busy transferring ; ; ; ; Reception data storage Reception mode Bus line output is no good. Set in the error state.
while_bit(BUSYFG) endw RCVDAT=SIO0 (A) if_bit(!RCVFLG) if_bit(!COI) SET1 ERRORF endif endif RET
167
78K/0 SERIES APPLICATION NOTE
;************************************ ;* INTCSI0 interrupt processing ;************************************ CSI_SEG CSEG INTCSI0: SEL RB0 if_bit(!RCVFLG) if_bit(!ACKD) ACKCT=#5 SET1 ACKWFG else CLR1 BUSYFG CLR1 ERRORF endif else SET1 ACKT CLR1 BUSYFG CLR1 ERRORF endif RETI ;************************************ ;* Time out processing ;************************************ TM3_SEG CSEG INTTM3: SEL RB0 if_bit(ACKWFG) if_bit(ACKD) CLR1 ACKWFG CLR1 BUSYFG else ACKCT-if(ACKCT==#0) SET1 ACKT SET1 ERRORF CLR1 ACKWFG CLR1 BUSYFG endif endif endif
; Transmission mode ; No acknowledge signal received ; Setting of the acknowledge signal wait state
; Release the busy state. ; Release the error state.
; Output the acknowledge signal. ; Release the busy state. ; Release the error state.
; ; ; ;
In the acknowledge signal wait state? Has the acknowledge signal been received? Release the acknowledge signal wait state. Release the busy state.
; Time out? ; Time out error processing ; Release the acknowledge signal wait state ; Release the busy state.
168
CHAPTER 8 SERIAL INTERFACE APPLICATION
8.3.2 Application as a Slave CPU Addresses, commands, and data are received from the master CPU and data are transmitted to the master CPU. In this example, the wakeup function is used and an address is received. A wakeup function is a function that generates an interrupt request signal only when the address transmitted by the master CPU matches the value set in the slave address register (SVA) while in the SBI mode. Consequently, INTCSI0 is generated only in the slave CPU selected by the master CPU. The slave CPUs that are not selected can be operated without generating a spurious interrupt request. When selected, a slave CPU releases the wakeup function (generates an interrupt request signal at the end of the transfer) and interfaces with the master CPU. In addition, discriminating addresses, commands, and data is done by testing bits 2 and 3 (RELD and CMDD) of the serial bus interface control register (SBIC). Because there is no automatic return to a state where no slave CPU is selected, a program is required that returns to the unselected state by, for example, command processing between the master and slaves. (1) Package description RCVDAT: Reception data storage area Bank 0: A
Name RCVDAT Stores the reception data Use Attributes SADDR Bytes 1

Name RCVFLG Reception mode setting Use
1 level, 3 bytes * Serial interface channel 0
169
78K/0 SERIES APPLICATION NOTE
* Serial interface channel 0 settings SBI mode, SB1 pin, wakeup mode Serial clock is the external clock input * Synchronous busy signal output * Set the SO0 latch to the high level. * Slave address * Enable serial interface channel 0 interrupt
CSIM0=#10010011B BYSE=1 RELT=1 SVA=#SLVADR
Generating INTCSI0 starts interrupt servicing. The following processing occurs in the interrupt servicing. * Address, command, and data discrimination * ACK signal output * Storing the receive data in RCVDAT. (2) Use example EXTRN EXTBIT RCVDAT RCVFLG
SLVADR EQU 5AH SB1 EQU P2.5 : : SET1 SB1 CSIM0=#10110100B SET1 RELT SET1 BSYE SVA=#SLVADR SIO0=#0FFH CLR1 SB1 CLR1 CSIMK0 EI
; ; ; ; ;
Select the external clock input, SB1 pin, wakeup mode Set the output latch to the high level. Set in the busy automatic output mode. Slave address setting Start serial transfer instruction
; Enable the serial interface channel 0 interrupt. ; Enable the master interrupt.
170
CHAPTER 8 SERIAL INTERFACE APPLICATION
(3) SPD chart
INTCSI0
Select register bank 0. IF : Address reception THEN Release the wakeup mode. Output the ACK signal. Address matching processing ELSE IF : Command reception THEN Command reception processing Output the ACK signal. ELSE IF : Reception mode THEN Data reception processing Output the ACK signal. ELSE Data transmission processing Save SIO0 data in memory.
171
78K/0 SERIES APPLICATION NOTE
(4) Program listing VECSI0 CSEG DW CSI_DAT DSEG RCVDAT: DS CSI_FLG BSEG RCVFLG DBIT AT 0EH INTCSI0 SADDR 1
; Vector address setting of serial interface channel 0 ; Receive data storage area
; Reception mode setting
CSI_SEG CSEG ;************************************ ;* INTCSI0 interrupt processing ;************************************ INTCSI0: SEL RB0 if_bit(RELD) ; Go to address reception. CLR1 WUP ; Release the wakeup mode. SET1 ACKT ; Output the acknowledge signal. ; User processing (address reception) ;************************************ elseif_bit(CMDD) ; Go to command reception. User processing (command reception) SET1 else if_bit(RCVFLG) User processing (data reception processing) SET1 ACKT ; Output the acknowledge signal. else ; User processing (data transmission processing) endif ;************************************ endif RCVDAT=SIO0 (A) RETI ACKT ; Output the acknowledge signal.
;
;
172
CHAPTER 8 SERIAL INTERFACE APPLICATION
8.4 3-WIRE SERIAL I/O MODE INTERFACE The function of the 3-wire serial I/O mode (serial clock, data input, data output) of serial channel 0 of the 78K/0 Series is used in communication between the master and slave CPUs. In this example, synchronized master-slave communication is demonstrated by adding one busy signal line as the handshake signal. The busy signal is active-low and is output by the slaves. In addition, data is 8 bits long and the MSB is transmitted first. An example using the PD78044F subseries is described. Figure 8-19. Connection Example of the 3-Wire Serial I/O Mode
Master
SCK0 SI0 SO0 BUSY
Slave
SCK0 SO0 SI0 BUSY
Figure 8-20. Communication Format of the 3-Wire Serial I/O Mode
BUSY
SCK0
SO0
DO7 DO6 DO5 DO4 DO3 DO2 DO1 DO0
SI0
DI7
DI6
DI5
DI4
DI3
DI2
DI1
DI0
173
78K/0 SERIES APPLICATION NOTE
8.4.1 Application as a Master CPU The serial clock is set to fX/2 4. Communication with the slave CPU is performed synchronized to this serial clock. After setting the transmission data, the master CPU begins the transfer. However, when the slave CPU is in the busy state (low busy signal), there is no transfer and the busy flag (BUSYFG) is set. (1) Package description TRANS : Name of the master 3-wire transfer subroutine TDATA : Transmission data storage area RDATA : Receive data storage area BUSY : Busy signal input port TREND : End of transfer test flag BUSYFG : Busy state test flag Interrupt bank 0 A Subroutine A
Name TDATA RDATA Use Stores the transmission data Stores the receive data Attributes SADDR Bytes 1

Name TREND BUSYFG Use End of transfer state setting Busy state setting
2 levels, 5 bytes * Serial interface channel 0 * P33
174
CHAPTER 8 SERIAL INTERFACE APPLICATION
* Serial interface channel 0 settings 3-wire serial I/O mode, MSB first * Serial clock f X/2 4 * Set the P27 output latch to the high level. * P33 input mode * Enable the serial interface channel 0 interrupt.
CSIM0=#10000011B TCL3=#xxxx1000B P27=1
The transmission data is set in TDATA and TRANS is called. After returning from the subroutine, the busy flag (BUSYFG) is tested. When the busy flag is set, the transfer must be repeated because no transfer was performed. In addition, when the busy flag is cleared, receive data is saved in RDATA because the transfer has ended.
175
78K/0 SERIES APPLICATION NOTE
(2) Use example
Set transmission data. UNTIL : BUSYFG is cleared Clear BUSYFG. Call TRANS. WHILE : TREND is cleared. Read in the receive data
EXTRN EXTBIT SCK0
TDATA,RDATA,TRANS TREND,BUSYFG,BUSY
EQU P2.7 : : CSIM0=#10000011B TCL3=#10001000B SET1 SCK0 SET1 PM3.3 CLR1 CSIMK0 EI : : TDATA=A repeat CLR1 BUSYFG CALL !TRANS until_bit(!BUSYFG) while_bit(!TREND) endw A=RDATA
; Set to 3-wire serial I/O mode and MSB first. ; Set to SCK0 = 262 kHz. ; Bit 3 of port 3 set in input mode ; Enable the serial interface channel 0 interrupt.
; Transmission data setting ; Busy test
; End of transfer ; Read in the received data.
(3) SPD chart
TRANS IF : Transfer is possible THEN Set transmission data in SIO0. ELSE Set in busy state. Set BUSYFG.
INTCSI0
Select register bank 0. Save SIO0 data in memory. Set in the end of transfer state. Set TREND.
176
CHAPTER 8 SERIAL INTERFACE APPLICATION
(4) Program listing PUBLIC CSEG DW EQU TRANS,RDATA,TDATA,BUSY,TREND,BUSYFG AT 0EH INTCSI0 ; Vector address setting of serial interface channel 0 0FF03H.3 ; 0FF03H = PORT 3 SADDR 1 1
VECSI0 BUSY
CSI_DAT DSEG RDATA: DS TDATA: DS
; Receive data storage area ; Transmission data storage area
CSI_FLG BSEG TREND DBIT BUSYFG DBIT CSI_SEG CSEG
; End of transfer state setting ; Busy state setting
;************************************ ;* INTCSI0 interrupt servicing ;************************************ INTCSI0: SEL RB0 RDATA=SIO0 (A) ; Save receive data. SET1 TREND ; Set in the end of transfer state. RETI ;************************************ ;* 3-wire (master) ;************************************ TRANS: if_bit(BUSY) ; Transfer possible state SIO0=TDATA (A) ; Set the transmission data. else SET1 BUSYFG ; Set in busy state. endif RET
177
78K/0 SERIES APPLICATION NOTE
8.4.2 Application as a Slave CPU Synchronous transmission/reception of 8-bit data is performed while synchronized to the serial clock from the master CPU. The busy signal from the slave CPU is output at a low level (busy state) while the transmission data is being prepared. The output timing of this busy signal releases the busy signal (high level) by setting the transmission data (CALL !TRANS). A busy signal (low level) is output as a result of interrupt servicing for INTCSI0 at the end of the transfer. Consequently, the busy state begins at the end of the transfer and lasts until the data is set. Figure 8-21. Busy Signal Output
Transmission During wait transmission
Preparing the transmission data
BUSY
Transmission data setting
INTCSI0
Transmission data setting
(1) Package description TRANS: Name of the slave 3-wire transfer subroutine TDATA : Transmission data storage area RDATA: Receive data storage area BUSY : Busy signal output port TREND: End of transfer test flag Interrupt bank 0 A Subroutine A
178
CHAPTER 8 SERIAL INTERFACE APPLICATION

Name TDATA RDATA Use Store the transmission data. Store the receive data. Attributes SADDR Bytes 1

Name TREND Use End of transfer state setting
2 levels, 5 bytes * Serial interface channel 0 * P33 * Serial interface channel 0 settings 3-wire serial I/O mode, MSB first, external clock input * P33 set in output mode * Busy state setting * Enable the serial interface channel 0 interrupt.
CSIM0=#10000000B P33=0
The transmission data is set in TDATA and TRANS is called. Because the busy signal is released in TRANS processing, the state to wait for communication with the master CPU is entered. After communication ends, interrupt service is started by generating INTCSI0. The end of the transfer can be verified by testing TREND. After TREND is set, the received data is saved in RDATA.
179
78K/0 SERIES APPLICATION NOTE
(2) Use example
Set transmission data. Call TRANS. WHILE : TREND is clear Read in the received data
EXTRN TDATA,RDATA,TRANS EXTBIT TREND,BUSY : : CSIM0=#10000000B CLR1 BUSY CLR1 PM3.3 CLR1 CSIMK0 EI : : TDATA=A CALL !TRANS while_bit(!TREND) endw A=RDATA (3) SPD chart
; ; ; ;
Set to the 3-wire serial I/O mode and MSB first. Busy state Bit 3 of port 3 set in output mode Enable the serial interface channel 0 interrupt.
; Transmission data setting ; End of transfer ; Read in the receive data
TRANS
Set transmission data in SIO0. Release the busy signal.
INTCSI0
Select register bank 0. Output the busy signal. Save SIO0 data in memory. Set in the end of transfer state.
180
CHAPTER 8 SERIAL INTERFACE APPLICATION
(4) Program listing PUBLIC PUBLIC CSEG DW RDATA,TDATA,BUSY,TREND,BUSYFG TRANS AT 0EH INTCSI0 ; Vector address setting of serial interface channel 0 SADDR 1 1
VECSI0
CSI_DAT DSEG RDATA: DS TDATA: DS CSI_FLG BSEG TREND DBIT BUSYFG DBIT BUSY EQU
; Receive data storage area ; Transmission data storage area
; End of transfer state setting ; Busy state setting 0FF03H.3 ; 0FF03H=PORT3
CSI_SEG CSEG ;************************************* ;* INTCSI0 interrupt servicing ;************************************* INTCSI0: SEL RB0 CLR1 BUSY ; Set in the busy state. RDATA=SIO0 (A) ; Save the receive data. SET1 TREND ; Set in the end of transfer state. RETI ;************************************* ;* 3-wire (slave) ;************************************* TRANS: SIO0=TDATA (A) ; Transmission data setting SET1 BUSY ; Release the busy state. RET
181
78K/0 SERIES APPLICATION NOTE
8.5 HALF-DUPLEX ASYNCHRONOUS COMMUNICATION The clocked serial interface channel 0 is used to perform half-duplex asynchronous communication. Two application examples are presented using the 3-wire mode and the SBI mode. The communication protocol is as follows. Transmission speed : Start bit : Character length : Parity bit : Stop bit : 9600 bps 1 bit 8 bits (LSB first) 1 bit (even/odd parity can be selected) 2 bits
Because the transmission speed is set to 9600 bps, 8-bit timer/event counter 2 is used to generate the serial clock. 8.5.1 Half-Duplex Asynchronous Communication of the 3-Wire Mode Figure 8-22 illustrates the system structure. Serial input and output is performed via the SI0 and SO0 pins, respectively. Bits 0 and 1 of port 3 are used as I/O for the BUSY signal. When the BUSY signal is `L,' serial communication is possible. Figure 8-22. System Structure (3-Wire Mode)
PD78044F
SO0 SI0 INTP1 P31 P30 Serial I/O
PD78044F
INTP1 SI0 SO0 P30 P31
Busy signal I/O
182
CHAPTER 8 SERIAL INTERFACE APPLICATION
(1) Transmission in the 3-wire mode Data transmission processing is explained below. <1> Start bit -> Transmission time wait based on the output latch operation of the serial interface and 8-bit timer/event counter 2 Caution To prevent a timing delay in data reception due to the loss of the start bit, assign high priority to the INTP1 interrupt request. <2> Data -> Transmission by the serial buffer
<3> Parity bit -> The output latch of the serial interface is manipulated in the interrupt servicing of 8-bit timer/event counter 2 and the parity bit is output. Caution To prevent a delay in the transmission timing, assign high priority to interrupt requests from 8-bit timer/event counter 2. <4> Stop bit -> The output latch of the serial interface in the interrupt servicing in 8-bit timer/event counter 2 is set and the stop bit is output. Caution To prevent a delay in the transmission timing, assign high priority to interrupt requests from 8-bit timer/event counter 2. Figure 8-23. 3-Wire Mode Transmission Format
Serial BUSY input pin P30 Output by the receiving side
Serial data output SO0
Start bit
D0
D1
D2
D3
D4
D5
D6
D7
Parity bit
Stop bits
Serial clock timer 2 interrupt request
Processing
Start operation of timer 2
Write data in SIO0
Enable INTCSI0 and timer 2 interrupts.
Disable timer 2 interrupt.
183
78K/0 SERIES APPLICATION NOTE
(2) Reception in the 3-wire mode The following example illustrates data reception processing. <1> Start bit -> Reception is started by a port test and the detection of a falling edge at the INTP1 pin.
Caution To prevent a timing delay in data reception due to the loss of the start bit, assign high priority to the INTP1 interrupt request. <2> Data -> Reception by the serial buffer
<3> Parity bit -> The port is tested in the interrupt servicing of 8-bit timer/event counter 2 and the parity bit is output. Caution To prevent a delay in reception timing, assign high priority to interrupt requests from 8-bit timer/event counter 2. <4> Stop bit -> The port is tested in the interrupt servicing for 8-bit timer/event counter 2 and the stop bit is output.
Caution To prevent a delay in reception timing, assign high priority to interrupt requests from 8-bit timer/event counter 2. When a parity error or an overrun error is generated, the flag is set. Figure 8-24. 3-Wire Mode Reception Format
Inverted by the serial interrupt. Serial BUSY output pin P31
Serial data input SI0
Start bit
D0
D1
D2
D3
D4
D5
D6
D7
Parity bit
Stop bits
Serial clock timer 2 interrupt request
Processing
Start timer 2 by INTP1 interrupt
Write FFH in SIO0 and disable INTP1.
Enable INTCSI0 and timer 2 interrupts.
Timer 2 interrupt
Disable timer 2 interrupt.
184
CHAPTER 8 SERIAL INTERFACE APPLICATION
(3) Package description * Subroutine names S_SOSHIN : Name of transmission subroutine S_JUSHIN : Name of reception subroutine * Input parameters SODATA : Stores transmission data F_PARITY : Indicates an even or odd parity selection state F_TUSHIN : Indicates a receiving or transmitting state * Output parameters JUDATA : Stores the receive data F_DATA : This is set after reception ends. F_ERRP : Indicates a parity error F_ERRE : Indicates an end bit error * I/O parameter F_PADATA : Stores the communication parity bit Bank 0 A Bank 1 A Bank 2 A
Name SODATA JUDATA C_WORK i j Use Transmission data storage area Receive data storage area State storage counter Work counter for loop operation Work counter for loop operation Attributes SADDR SADDR SADDR SADDR SADDR Bytes 1 1 1 1 1
185
78K/0 SERIES APPLICATION NOTE

Name F_PARITY F_PADATA F_TUSHIN F_ERRP F_ERRE F_DATA F_WORK Parity selection flag Parity bit storage flag Communication flag Parity error flag End bit error flag End of reception flag Work flag Use Set when odd parity is selected. Stores the parity. Set during communication. Set when a parity error occurs. Set when an end bit error occurs. Set at the end of reception. For work
1 level, 3 bytes * Serial interface channel 0 (3-wire mode) * 8-bit timer/event counter 2 * External interrupt edge detection (INTP1 pin) * Set in the S_SOSHIN and S_JUSHIN subroutines. * Port 2: bit 5 input port; bit 6 output port settings * Port 3: bit 0 input port; bit 1 output port settings * Serial interface channel 0 settings 3-wire mode, serial clock = 8-bit timer/event counter 2 selection * 8-bit timer/event counter 2 setting 9600-bps baud rate setting 8-bit timer register x 2-channel mode 8-bit timer/event counter 2 operation disabled * * * * INTP1 setting INTP1 falling edge High priority 8-bit timer/event counter 2 interrupt High priority INTP1 interrupt Serial interface interrupt enabled
PM2=#x01xxxxxB PM3=#xxxxxx01B CSIM0=#10000110B CR20=#54 TCL1=#01100000B TOC1=#00000000B TMC1=#00000000B INTM0=#00000000B CLR1 TMPR2 CLR1 PPR1 CLR1 CSIMK0
186
CHAPTER 8 SERIAL INTERFACE APPLICATION
* Set in the following order when starting data transmission or reception. * Starting data transmission <1> Store the transmission data in the SODATA area. <2> Set the transmission flag. <3> Call the S_SOSHIN subroutine. * Starting data reception <1> Clear the communication flag (F_TUSHIN). (Set to 0.) <2> Invert the BUSY signal. <3> Call the S_JUSHIN subroutine. * When interrupt requests other than those in the 78K/0 Series package are used, to enable high priority interrupts, set the ISP flag to 0 at the beginning of interrupt processing and enable interrupts.
187
78K/0 SERIES APPLICATION NOTE
(4) Use example This example illustrates selecting an even or odd parity bit and selecting transmission or reception by using key input. EXTRN SODATA EXTRN JUDATA,S_SOSHIN,S_JUSHIN EXTBIT F_PARITY,F_DATA,F_PADATA,F_TUSHIN EXTBIT F_ERRE,F_ERRP ; BUSY_O EQU P3.1 BUSY_I EQU P3.0 PARIKEY EQU 22 ; Decoded parity key value JYUSHIN EQU 21 ; Decoded reception key value TUSHIN EQU 20 ; Decoded transmission key value ;*************************************** ; Initialize ;*************************************** VERES CSEG AT 00H DW RES_STA M3 CSEG ; RES_STA: ; MOV P2,#0BFH ; P2.5=H,P2.6=L MOV P3,#0FFH ; MOV PM2,#00100000B ; P2.5 = input port, P2.6 = output port MOV PM3,#00000001B ; P3.0 = input port, P3.1 = output port ;***8-bit timer register settings*** CR20=#54 ; TCL1=#01100000B ; 1.05-MHz count clock TOC1=#00000000B ; TMC1=#00000000B ; 8-bit timer register selection, timer 2 operation disabled ;***Serial interface 0 settings*** CSIM0=#10000110B ; 3-wire mode, serial clock selection, 8-bit timer 2 SET1 RELT ; ;***INTP1 settings*** INTM0=#00000000B ; INTP1 falling edge CLR1 TMPR2 ; High priority timer 2 interrupt CLR1 PPR1 ; High priority INTP1 interrupt CLR1 PIF1 ; Clear the INTP1 request flag. CLR1 TMIF2 ; Clear the timer 2 request flag. CLR1 CSIIF0 ; Clear the serial interface request flag. CLR1 CSIMK0 ; Enable the serial interface interrupt. while(forever) ; . ; . ;
188
CHAPTER 8 SERIAL INTERFACE APPLICATION
if_bit(F_KEYON) switch(M_KEYON) case PARIKEY: SET1 CY CY ^=F_PARITY F_PARITY=CY break case TUSHIN: SET1 F_TUSHIN CLR1 F_SOEND break case JYUSHIN: CLR1 F_TUSHIN CY=BUSY_0 NOT1 CY BUSY_0=CY if_bit(CY) SET1 PMK1 else CLR1 F_ERRP CLR1 F_ERRE CALL !S_JUSHIN endif break ends endif . . . if_bit(!F_SOEND) if_bit(F_TUSHIN) CY=BUSY_I if_bit(!CY) SODATA=#0 SET1 F_SOEND SODATA=WORK CALL !S_SOSHIN endif endif endif
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
Is the key on flag 1? The pressed key was the parity key. Invert the even/odd parity decision
The pressed key was the communication key. Set the communication flag (during transmission).
The pressed key was the reception key. Clear the communication flag (during reception) Inverted BUSY signal data is output.
INTP1 interrupt is disabled.
; ; Is the communication flag set? ; Is the BUSY signal inactive? ; ; ; ; Transmission data storage area <- transmission data ; ; ;
189
78K/0 SERIES APPLICATION NOTE
(5) SPD chart [Reception subroutine]
S_JUSHIN
Clear INTP1 request flag. Enable INTP1 interrupt.
[Transmission subroutine]
S_SOSHIN
if (odd parity is selected) THEN Set the parity data flag. for (i = #0 ; i < #8 ; i+ +) CY <- Least significant bit of the transmission data The exclusive-OR is taken of CY and the parity data flag. Transfer the result to the parity data flag. The timer output flip-flop of 8-bit timer/event counter 2 is reset and the inversion operation is enabled. Clear request flag of 8-bit timer/event counter 2. Disable interrupts. Enable 8-bit timer/event counter 2 operation. Transmit the start bit. Wait the time it takes to transmit the start bit. SIO0 <- transmission data Enable interrupts.
190
CHAPTER 8 SERIAL INTERFACE APPLICATION
[Parity end bit communication processing (8-bit timer/event counter 2 interrupt)]
TAIMA2
Switch to bank 1. if (transmitting data) THEN switch (What data is being transmitted?) [case : 1] Parity data transmission [case : 2] First end bit transmission [case : 3] Second end bit transmission Disable 8-bit timer/event counter 2 interrupt. Disable operation of 8-bit timer/event counter 2. switch (What data is being received?) [case : 1] Parity data read [case : 2] if (Is first end bit error present?) THEN Set end bit error flag. [case : 3] if (Is second end bit error present?) THEN Set end bit error flag. Disable 8-bit timer/event counter 2 interrupt. Disable operation of 8-bit timer/event counter 2. if (Does parity data match?) THEN if (Is end bit present?) THEN Set end of reception flag. ELSE Set parity error flag.
191
78K/0 SERIES APPLICATION NOTE
[Data transmission/reception completion processing]
INTSI0
Switch to bank 2. Clear 8-bit timer/event counter 2 request flag. Enable 8-bit timer/event counter 2 interrupt. Output 'H' to the BUSY0 signal. if (receiving) THEN Read in receive data.
[Startup processing for data reception (INTP1 interrupt processing)]
INTP1
Switch to bank 1. Clear the 8-bit timer/event counter 2 request flag. Clear the 8-bit timer 2 counter. Enable the operation of 8-bit timer/event counter 2. Wait the time to read the start bit. if (Is the INTP1 pin asserted?) THEN Disable INTP1 interrupt. Read preparation for receive data
192
CHAPTER 8 SERIAL INTERFACE APPLICATION
(6) Program listing PUBLIC PUBLIC PUBLIC PUBLIC ; VEINTP1 VEINTSI0 VETIM2 F_PADATA,F_PARITY F_DATA,F_TUSHIN JUDATA,SODATA,S_JUSHIN,S_SOSHIN F_ERRP,F_ERRE CSEG DW CSEG DW CSEG DW AT 08H INTP AT 0EH INTSI0 AT 18H TAIMA2
; INTP1 vector address setting ; Vector address setting of serial interface channel 0
; Vector address setting of 8-bit timer 2 ; SI0 EQU P2.5 BUSY_0 EQU P3.1 BUSY_1 EQU P3.0 ; MORAM DSEG SADDR SODATA: DS 1 ; Transmission data storage area C_WORK: DS 1 ; Work counter JUDATA: DS 1 ; Received data storage area i: DS 1 ; Work counter k: DS 1 ; Work counter ; MOFLG BSEG F_PARITY DBIT ; Parity selection flag F_ERRP DBIT ; Parity error flag F_ERRE DBIT ; End bit error flag F_DATA DBIT ; End of reception flag F_PADATA DBIT ; Parity data flag F_WORK DBIT ; Work flag F_TUSHIN DBIT ; Communication flag ;********************************** ; Reception routine ;********************************** JUSHIN CSEG ; S_JUSHIN: ; CLR1 PIF1 ; Clear INTP1 request flag. CLR1 PMK1 ; Enable the INTP1 interrupt. RET ;
193
78K/0 SERIES APPLICATION NOTE
;************************************ ; Transmission routine ;************************************ SOSHIN CSEG S_SOSHIN: ; CLR1 F_PADATA ; Clear parity data. if_bit(F_PARITY) ; Is odd parity selected? SET1 F_PADATA ; Set parity data. endif ; A=SODATA ; for(i=#0;i<#8;i++) ; Determine parity data. RORC A,1 ; CY ^=F_PADATA ; F_PADATA = CY ; next ; TOC1=#01100000B (A) ; CLR1 TMIF2 ; Clear timer 2 request flag. DI ; SET1 TCE2 ; Enable 8-bit timer operation. SET1 CMDT ; Transmit the start bit. while_bit(!TMIF2) ; Wait for the start bit to be transmitted. endw ; CLR1 TMIF2 ; SIO0=SODATA (A) ; Start data transmission. EI ; RET ; ;************************************ ; Timer 2 interrupt servicing ;************************************ TIM2 CSEG ; TAIMA2: ; SEL RB1 ; Set to bank 1. if_bit(F_TUSHIN) ; Is the communication flag set? if(C_WORK <= #4) ; Work counter contents switch(C_WORK) ; 0: parity data transmission case 0: ; if_bit(F_PADATA) ; SET1 RELT ; else ; SET1 CMDT ; endif ; break ; case 2: ; 2: end bit transmission SET1 RELT ; Transmit `H.' break ; case 4: ; 4: end bit transmission SET1 RELT ; Transmit `H.' SET1 TMMK2 ; Disable timer 2 interrupt. CLR1 TCE2 ; Disable 8-bit timer operation. C_WORK=#0 ; break ; ends ; C_WORK++ ; else ; C_WORK=#0 ; endif 194
CHAPTER 8 SERIAL INTERFACE APPLICATION
else if(C_WORK <= #6) switch(C_WORK) case 1: CY=SI0 F_PADATA=CY break case 3: if_bit(!SI0) SET1 F_ERRE endif break case 5: if_bit(!SI0) SET1 F_ERRE endif C_WORK=#0 SET1 TMMK2 CLR1 TCE2 CLR1 F_WORK if_bit(F_PARITY) SET1 F_WORK endif A=JUDATA for(i=#0;i<#8;i++) RORC A,1 CY ^= F_WORK F_WORK = CY next CLR1 F_ERRP CLR1 F_DATA F_WORK ^= F_PADATA (CY) if_bit(!F_WORK) if_bit(!F_ERRE) SET1 F_DATA endif else SET1 F_ERRP endif break ends C_WORK++ else C_WORK=#0 endif endif RETI
; ; Receiving? ; Work counter contents ; 1: read in parity data ; ; ; ; 3: check the end bit ; If an error is present, set the end bit error flag. ; ; ; ; 5: check the end bit ; If an error is present, set the end bit error flag. ; ; ; ; Disable timer 2 interrupt. ; Disable 8-bit timer operation. ; ; ; ; ; ; Store in the receive data. ; ; ; ; ; ; ; ; Check parity data. ; Check end bit data. ; ; ; If parity data matches, set F_DATA. ; If the parity data does not match, set the parity error flag. ; ; ; ; ; ; ; ; ;
195
78K/0 SERIES APPLICATION NOTE
;********************************************* ; INTSI0 interrupt servicing (reception) ;********************************************* S_SI0 CSEG ; INTSI0: ; SEL RB2 ; Set to bank 2. CLR1 TMIF2 ; Clear timer 2 request flag. CLR1 TMMK2 ; Enable timer 2 interrupt. SET1 BUSY_0 ; Output high BUSY signal. if_bit(!F_TUSHIN) ; JUDATA=SIO0 (A) ; endif ; C_WORK=#0 ; Clear the work counter to zero. RETI ; ;********************************************* ; INTP1 interrupt servicing (reception) ;********************************************* S_P1 CSEG ; INTP1: ; SEL RB1 ; CLR1 TMIF2 ; Clear timer 2 request flag. CLR1 TCE2 ; Clear timer 2 counter. SET1 TCE2 ; Enable timer operation. while_bit(!TMIF2) ; endw ; CLR1 TMIF2 ; if_bit(!SI0) ; INTP1 chattering processing TOC1=#10100000B ; SET1 PMK1 ; Disable INTP1 interrupt. SIO0=#0FFH ; endif ; RETI ; END
196
CHAPTER 8 SERIAL INTERFACE APPLICATION
8.5.2 Half-Duplex Asynchronous Communication in the SBI Mode Figure 8-25 shows the system structure. Serial input and output are performed via pin SB0. Bits 0 and 1 of port 3 are used for input and output of the BUSY signal. When the BUSY signal is low, serial communication is possible. Cautions concerning the use of the SBI mode are given below. <1> Set bit 5 of port 2 (SB0) in the output mode when reset starts. However, when the SB0 port is tested, set SB0 in the input mode. At the end of port testing, set in the output mode again. <2> After the last stop bit is transmitted and detected in serial communication, enable serial operation again after it has been disabled. Essentially, the end of SBI communication is determined by checking the ready signal after detecting the acknowledge signal. However, because the acknowledge signal is used in transmitting and receiving the parity bit, when a `1' parity bit is transmitted and received, the condition for the end of SBI communication does not hold. When this is not considered to be the end of serial communication, sometimes the next communication does not operate normally. Figure 8-25. System Structure (SBI Mode)
PD78044F
Serial I/O SB0 INTP1 P31 P30 BUSY signal I/O SB0 INTP1 P30 P31
PD78044F
197
78K/0 SERIES APPLICATION NOTE
(1) Transmission in the SBI mode Data transmission processing is shown below. <1> Start bit -> Transmission time wait based on the output latch operation of the serial interface and 8-bit timer/event counter 2 Caution To prevent a timing delay in data reception due to the loss of the start bit, assign high priority to the INTP1 interrupt request. <2> Data and parity bits -> 9-bit transmission by the serial buffer and the acknowledge signal <3> Stop bit -> The output latch of the serial interface is set in the interrupt servicing of 8-bit timer/event counter 2 and the stop bit is output. Cautions 1. To prevent delays in the transmission timing, assign high priority to an interrupt request from 8-bit timer/event counter 2. 2. If the second stop bit has been transmitted, enable operation again after serial operation for verifying the end of transmission is disabled once. Figure 8-26. SBI Mode Transmission Format
Serial BUSY input pin P30 Output by the receiving side Start bit
Serial data output SB0
D0
D1
D2
D3
D4
D5
D6
D7
Parity bit
Stop bit
Serial clock timer 2 interrupt request
Processing
Start timer 2 operation.
Write the parity bit to ACKE. Write to SIO0.
Enable the INTCSI0 and timer 2 interrupts.
Disable the timer 2 interrupt.Note
Note After serial operation is disabled once, set again to enable.
198
CHAPTER 8 SERIAL INTERFACE APPLICATION
(2) Reception in the SBI mode Data reception processing is shown below. <1> Start bit -> Start reception by detecting a falling edge at pin INTP1 and testing the port Cautions 1. When testing the port, set in the following order. <1> Set bit 5 (SI0) of port 2 to an input port. <2> Test the port and write to SIO0. <3> Reset bit 5 of port 2 in the output mode. 2. To prevent delayed timing in data reception due to the loss of the start bit, assign high priority to the INTP1 interrupt request. <2> Data and parity bits -> Reception by the serial buffer and acknowledge detection <3> Stop bit -> Test the port in interrupt servicing for 8-bit timer/event counter 2 and output the parity bit. Cautions 1. To prevent delays in the transmission timing, assign high priority to an interrupt request from 8-bit timer/event counter 2. 2. If the second stop bit has been transmitted, enable operation again after serial operation for verifying the end of transmission is disabled once. When a parity or an overrun error occurs, set the flag. Figure 8-27. SBI Mode Reception Format
Invert at the serial interrupt. Serial BUSY output pin P31
Serial data input SB0
Start bit
D0
D1
D2
D3
D4
D5
D6
D7
Parity bit
Stop bits
Serial clock timer 2 interrupt request
Processing
Start INTP1 Write FFH to SIO0 and disable INTP1. interrupt timer 2
Enable the Timer 2 interrupt INTCSI0 and timer 2 interrupts. Disable Timer 2 interrupt.
199
78K/0 SERIES APPLICATION NOTE
(3) Package description * Subroutine names S_SOSHIN : Name of transmission subroutine S_JUSHIN : Name of reception subroutine * Input parameters SODATA : Stores transmission data F_PARITY : Indicates even and odd parity selection state F_TUSHIN : Indicates the busy receiving or transmitting state * Output parameters JUDATA : Stores receive data F_DATA : If reception is over, this is set. F_ERRP : Indicates a parity error F_ERRE : Indicates an end bit error * I/O parameter F_PADATA : Stores the parity bit for communication Bank 0 A Bank 1 A Bank 2 A
Name SODATA JUDATA C_WORK i j Use Transmission data storage area Receive data storage area State storage counter Work counter for loop operation Work counter for loop operation Attributes SADDR SADDR SADDR SADDR SADDR Bytes 1 1 1 1 1
200
CHAPTER 8 SERIAL INTERFACE APPLICATION

Name F_PARITY F_PADATA F_TUSHIN F_ERRP F_ERRE F_DATA F_WORK Parity selection flag Parity bit storage flag Communication flag Parity error flag End bit error flag End of reception flag Work flag Use Set when odd parity is selected. Stores the parity. Set during communication. Set when a parity error occurs. Set when an end bit error occurs. Set at the end of reception. For work
1 level, 3 bytes * Serial interface channel 0 (SBI mode) * 8-bit timer/event counter 2 * External interrupt edge detection (INTP1 pin) * After a reset start at the pin (P25) for I/O data, set the following before the serial transmission of the first byte. <1> Set the output latch of P25 to 1. <2> Set bit 0 (RELT) of the serial bus control register (SBIC) to 1. <3> This time, set the output latch of the P25 set to 1 to 0. * Set in the S_SOSHIN and S_JUSHIN subroutines. * Port 2: bit 5 input port, bit 6 output port settings PM2=#x01xxxxxB * Port 3: bit 0 input port, bit 1 output port settings PM3=#xxxxxx01B * Serial interface channel 0 setting SBI mode, serial clock = 8-bit timer 2 selection CSIM0=#10010110B * 8-bit timer/event counter 2 settings 9600-bps baud rate setting CR20=#54 8-bit timer register x 2-channel mode TCL1=#01100000B 8-bit timer/event counter 2 operation disabled TOC1=#00000000B TMC1=#00000000B * INTP1 setting INTP1 falling edge INTM0=#00000000B * High-priority 8-bit timer/event counter 2 interrupt CLR1 TMPR2 * High-priority INTP1 interrupt CLR1 PPR1 * Enable serial interface interrupt CLR1 CSIMK0
201
78K/0 SERIES APPLICATION NOTE
* Set the following order when starting data transmission and reception. * Starting data transmission <1> Store transmission data in the SODATA area. <2> Set transmission flag. <3> Call the S_SOSHIN subroutine. * Starting data reception <1> Clear the communication flag (F_TUSHIN). (Set to 0.) <2> Invert the busy signal. <3> Call the S_JUSHIN subroutine. * When interrupt requests other than those in the 78K/0 Series package are used, to enable high priority interrupts, set the ISP flag to 0 at the beginning of interrupt processing and enable interrupts.
202
CHAPTER 8 SERIAL INTERFACE APPLICATION
(4) Use example This example illustrates selecting an even or odd parity bit and selecting transmission or reception by using key input. EXTRN SODATA EXTRN JUDATA,S_SOSHIN,S_JUSHIN EXTBIT F_PADATA,F_PARITY,F_DATA,F_TUSHIN EXTBIT F_ERRP,F_ERRE ; TUSHIN EQU 20 JYUSHIN EQU 21 PARIKEY EQU 22 BUSY_O EQU P3.1 BUSY_I EQU P3.0 SB0 EQU P2.5 ;************************************** ; Initialize ;************************************** M3S CSEG ; RES_STA: ; MOV P2,#9FH ; P2.5=L, P2.6=L MOV P3,#0FFH ; MOV PM2,#00000000B ; P2.5 = output mode MOV PM3,#00000001B ; P3.0 = input port, P3.1 = output port ;***8-bit timer register setting*** CR20=#54 ; TCL1=#01100000B ; 1.05-MHz count clock TOC1=#00000000B ; TMC1=#00000000B ; 8-bit timer register selection and timer 2 operation disable ;***Serial interface 0 settings*** SET1 SB0 ; CSIM0=#10000110B ; SBI mode, serial clock selection, 8-bit timer 2 SET1 RELT ; CLR1 SB0 ; ;***INTP1 settings*** CLR1 TMPR2 ; High priority timer 2 interrupt CLR1 PPR1 ; High priority INTP1 interrupt INTM0=#00000000B ; INTP1 falling edge CLR1 PIF1 ; Clear the INTP1 request flag. CLR1 TMIF2 ; Clear the timer 2 request flag. CLR1 CSIIF0 ; Clear the serial interface request flag. CLR1 KSIF ; Clear the interrupt request flag. CLR1 CSIMK0 ; Enable serial interface interrupt. CLR1 KSMK ; Enable INTKS interrupt.
203
78K/0 SERIES APPLICATION NOTE
while(forever) . . if_bit(F_KEYON) switch(M_KEYON) case PARIKEY: SET1 CY CY ^= F_PARITY F_PARITY=CY break case TUSHIN: SET1 F_TUSHIN CLR1 F_SOEND break case JYUSHIN: CLR1 F_TUSHIN CY=BUSY_0 NOT1 CY BUSY_0=CY it_bit(CY) SET1 PMK1 else CLR1 F_ERRP CLR1 F_ERRE CALL !S_JUSHIN endif break ends endif . . if_bit(!F_SOEND) if_bit(F_TUSHIN) CY=BUSY_I if_bit(!CY) SET1 F_SOEND SODATA=#0 SODATA=WORK (A) CALL !S_SOSHIN endif endif endif
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
Is the key on flag 1? The pressed key was the parity key. Invert odd or even parity decision
The pressed key was the communication key. Set the communication flag (while transmitting).
The pressed key was the reception key. Clear the communication flag (while receiving). Output the inverted BUSY signal data.
Disable INTP1 interrupt.
; Is the communication flag set? ; Is the BUSY signal inactive? ; ; ; ; ; Transmission data storage area <- transmission data ; Call the transmission routine. ; ; ;
204
CHAPTER 8 SERIAL INTERFACE APPLICATION
(5) SPD chart [Reception subroutine]
S_JUSHIN
Clear INTP1 request flag. Enable INTP1 interrupt.
[Transmission subroutine]
S_SOSHIN
Reverse the direction of the transmission data. if (odd parity is selected) THEN Set parity data flag. for (i = #0 ; i < #8 ; i++) CY <- Least significant bit of the transmission data The exclusive-OR is taken of CY and the parity data flag. Transfer the result to the parity data flag. The timer output flip-flop of 8-bit timer/event counter 2 is reset and the inverse operation is enabled. Clear request flag of 8-bit timer 2. Disable interrupts. Enable 8-bit timer 2 operation. Transmit start bit. Wait the time the start bit is transmitted. ACKE <- parity bit data SIO0 <- transmission data Enable interrupts.
205
78K/0 SERIES APPLICATION NOTE
[Stop bit transmission/reception processing (8-bit timer/event counter 2 interrupt servicing)]
TAIMA2
Switch to bank 1. if (data is being transmitted) THEN switch (What data is being transmitted?) [case : 1] First end bit transmission [case : 2] Second end bit transmission Disable 8-bit timer counter 2 interrupt. Disable operation of 8-bit timer 2. switch (What data is being received?) [case : 1] if (Is the first end bit error present?) THEN Set end bit error flag. [case : 2] if (Is the second end bit error present?) THEN Set end bit error flag. Disable 8-bit timer counter 2 interrupt. Disable operation of 8-bit timer 2. if (Does the parity data match?) THEN Set end of reception flag. ELSE Set parity error flag.
206
CHAPTER 8 SERIAL INTERFACE APPLICATION
[Data transmission/reception completion processing (INTSI0 interrupt servicing)]
INTSI0
Switch to bank 2. Clear 8-bit timer 2 request flag. Enable 8-bit timer 2 interrupt. Output the high level to the BUSY0 signal. if (receiving) THEN Read in received data. Reverse the received data that was read in. Read in parity data.
[Starting processing for data reception (INTP1 interrupt servicing)]
INTP1
Switch to bank 1. Clear 8-bit timer 2 counter. Enable operation of 8-bit timer 2. Wait the time for the start bit to be read in. if (Is the INTP1 pin asserted?) THEN Clear the 8-bit timer 2 request flag. Disable INTP1 interrupt. Received data read preparation
207
78K/0 SERIES APPLICATION NOTE
(6) Program listing PUBLIC PUBLIC PUBLIC PUBLIC ; VEINTP1 VEINTSI0 VETIM2 JUDATA SODATA,F_PARITY,S_SOSHIN F_DATA,S_JUSHIN,F_PADATA,F_TUSHIN F_ERRE,F_ERRP CSEG DW CSEG DW CSEG DW AT 08H INTP1 AT 0EH INTSI0 AT 18H TAIMA2
; SB0 EQU P2.5 BUSY_O EQU P3.1 BUSY_I EQU P3.0 PORT25 EQU PM2.5 ; MOSRAM DSEG SADDR SODATA: DS 1 ; C_WORK: DS 1 ; JUDATA: DS 1 ; i: DS 1 ; k: DS 1 ; ; MOSFLG BSEG F_ERRP DBIT ; F_ERRE DBIT ; F_DATA DBIT ; F_PADATA DBIT ; F_PARITY DBIT ; F_WORK DBIT ; F_TUSHIN DBIT ; ; ;********************************* ; Reception routine ;********************************* JUSHIN CSEG ; S_JUSHIN: ; CLR1 PIF1 ; CLR1 PMK1 ; RET ;
Transmission data storage area Work counter Receive data storage area Work counter Work counter
Parity error flag End bit error flag End of reception flag Parity data flag Parity selection flag Flag work area Communication flag
Clear the request flag. Enable INTP1 interrupt.
208
CHAPTER 8 SERIAL INTERFACE APPLICATION
; ;************************************** ; Transmission routine ;************************************** SOSHIN CSEG S_SOSHIN: ; A=SODATA ; Reverse the direction of the transmission data. SODATA=#0 ; if_bit(A.7) ; SET1 SODATA.0 ; endif ; if_bit(A.6) ; SET1 SODATA.1 ; endif ; if_bit(A.5) ; SET1 SODATA.2 ; endif ; if_bit(A.4) ; SET1 SODATA.3 ; endif ; if_bit(A.3) ; SET1 SODATA.4 ; endif ; if_bit(A.2) ; SET1 SODATA.5 ; endif ; if_bit(A.1) ; SET1 SODATA.6 ; endif ; if_bit(A.0) ; SET1 SODATA.7 ; endif ; CLR1 F_PADATA ; Clear the parity data flag. if_bit(F_PARITY) ; Is odd parity currently selected? SET1 F_PADATA ; Set the parity data. endif ; A=SODATA ; for(k=#0;k<#8;k++) ; Parity data setting. RORC A,1 ; CY ^= F_PADATA ; F_PADATA = CY ; next ; TOC1=#01100000B (A) ; CLR TMIF2 ; Clear the timer 2 request flag. DI ; SET1 TCE2 ; Enable 8-bit timer operation. SET1 CMDT ; Start bit transmission. while_bit(!TMIF2) ; Wait the time for the start bit to be transmitted. endw ; CLR1 TMIF2 ; SET1 ACKE ; Clear acknowledge. if_bit(F_PADATA) ; Clear acknowledge when parity data is 1. CLR1 ACKE ; endif ; SIO0=SODATA (A) ; Start data transmission EI ; RET ; 209
78K/0 SERIES APPLICATION NOTE
; ;********************************** ; Timer 2 interrupt servicing ;********************************** TIM2 CSEG ; TAIMA2: ; SEL RB1 ; Set to bank 1. if_bit(F_TUSHIN) ; Busy communicating? if(C_WORK < #3) ; Work mode contents switch(C_WORK) ; 0: end bit transmission case 0: ; SET1 RELT ; break ; case 2: ; 2: end bit transmission SET1 RELT ; Disable 8-bit timer 2 interrupt. SET1 TMMK2 ; CLR1 TCE2 ; Disable 8-bit timer 2 operation. SET1 SB0 ; Set bit 5 of port 2 to an input port. CLR1 CSIE0 ; Disable serial operation. SET1 CSIE0 ; Enable serial operation. SET1 RELT ; CLR1 SB0 ; Set bit 5 of port 2 to an output mode. C_WORK=#0 ; break ; ends ; C_WORK++ ; else ; C_WORK=#0 ; endif ;
210
CHAPTER 8 SERIAL INTERFACE APPLICATION
; if(C_WORK < #4) ; SET1 PORT25 ; switch(C_WORK) ; case 1: ; if_bit(!SB0) ; SET1 F_ERRE ; endif ; break ; case 3: ; if_bit(!SB0) ; SET1 F_ERRE ; endif ; SET1 SB0 ; CLR1 CSIE0 ; SET1 CSIE0 ; SET1 RELT ; CLR1 SB0 ; C_WORK=#0 ; SET1 TMMK2 ; CLR1 TCE2 ; CLR1 F_WORK ; if_bit(F_PARITY) ; SET1 F_WORK ; endif ; A=JUDATA ; for(i=#0;i<#8;i++) ; RORC A,1 ; CY ^= F_WORK ; F_WORK = CY ; next ; CLR1 F_ERRP ; CLR1 F_DATA ; F_WORK ^= F_PADATA (CY) ; if_bit(!F_WORK) ; if_bit(!F_ERRE) ; SET1 F_DATA ; endif ; else ; SET1 F_ERRP ; endif ; CLR1 F_WORK ; break ; ends ; CLR1 PORT25 ; C_WORK++ ; else ; C_WORK=#0 ; endif ; endif ; RETI else
Busy receiving? Set bit 5 of port 2 to an input port. Work mode contents 1: If the end bit is high, set the end bit error flag.
3: If the end bit is high, set the end bit error flag.
Bit 5 of port 2 = High Disable serial operation. Enable serial operation. Bit 5 of port 2 = Low Disable 8-bit timer 2 interrupt. Disable 8-bit timer operation.
Store in the receive data.
Check parity data. If a normal reception, set the F_DATA flag.
If a parity error occurs, set the F_ERRP flag.
Set bit 5 of port 2 to an output port.
211
78K/0 SERIES APPLICATION NOTE
; ;********************************************* ; INTSI0 interrupt servicing (reception) ;********************************************* S_SI0 CSEG ; INTSI0: ; SEL RB2 ; CLR TMIF2 ; Clear timer 2 request flag. CLR1 TMMK2 ; Enable timer 2 interrupt. SET1 BUSY_O ; if_bit(!F_TUSHIN) ; A=SIO0 ; JUDATA=#0 ; if_bit(A.7) ; Reread the receive data in reverse. SET1 JUDATA.0 ; endif ; if_bit(A.6) ; SET1 JUDATA.1 ; endif ; if_bit(A.5) ; SET1 JUDATA.2 ; endif ; if_bit(A.4) ; SET1 JUDATA.3 ; endif ; if_bit(A.3) ; SET1 JUDATA.4 ; endif ; if_bit(A.2) ; SET1 JUDATA.5 ; endif ; if_bit(A.1) ; SET1 JUDATA.6 ; endif ; if_bit(A.0) ; SET1 JUDATA.7 ; endif ; CLR1 F_PADATA ; Read in the parity data. CY=ACKD ; NOT1 CY ; F_PADATA=CY ; endif ; C_WORK=#0 ; RETI ;
212
CHAPTER 8 SERIAL INTERFACE APPLICATION
;********************************************* ; INTP1 interrupt servicing (reception) ;********************************************* S_P1 CSEG ; INTP1: ; SEL RB1 ; CLR1 TMIF2 ; Clear timer 2 request flag. CLR1 TCE2 ; Clear timer 2 counter. SET1 TCE2 ; Enable timer operation. while_bit(!TMIF2) ; endw ; CLR1 TMIF2 ; SET1 PORT25 ; Set port to an input port. if_bit(!SB0) ; Chattering processing of INTP1 CLR1 ACKE ; TOC1=#10100000B ; SET1 PMK1 ; Disable INTP1 interrupt. SIO0=#0FFH ; endif ; CLR1 PORT25 ; Set bit 5 of port 2 to an output port. RETI ; END
213
78K/0 SERIES APPLICATION NOTE
[MEMO]
214
CHAPTER 9 A/D CONVERTER APPLICATION
CHAPTER 9 A/D CONVERTER APPLICATION
The A/D converter in the 78K/0 Series has 8-bit resolution and eight channels, and is a successive approximation type. Its only operating mode is the select mode, but the start of conversion can also be specified by using an external trigger. In addition, when there is no external trigger, the selected channel is repeated and A/D conversion is performed. The A/D converter is set by the A/D converter mode registers (ADM and ADM0), A/D converter input selection register (ADIS), and analog input channel specification register (ADS0).
* *
Cautions 1. ADM0 and ADS0 are incorporated into the PD780228 subseries only. 2. The format of the registers incorporated into the PD780228 subseries differs from that of the PD78044F, PD78044H, and PD780208 subseries. When using any of the sample programs described in this chapter with the PD780228 subseries, replace the register settings with those for the PD780228 subseries.
215
78K/0 SERIES APPLICATION NOTE
Figure 9-1. Format of the A/D Converter Mode Register (PD78044F, PD78044H, and PD780208 Subseries)
Symbol ADM 7 CS 6 TRG 5 FR1 4 FR0 3 2 1 0 1 Address FF80H At reset 01H R/W R/W
ADM3 ADM2 ADM1
ADM3 ADM2 ADM1 Analog input channel selection 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 ANI0 ANI1 ANI2 ANI3 ANI4 ANI5 ANI6 ANI7
FR1
FR0
A/D conversion time selectionNote 1 With fX = 5.0 MHz With fX = 4.19 MHz 160/fX (38.1 s) 80/fX (19.1 s) 200/fX (47.7 s)
0 0 1 1
0 1 0 1
160/fX (32.0 s) 80/fX (Setting prohibitedNote 2) 200/fX (40.0 s) Setting prohibited
TRG 0 1
External trigger selection No external trigger (software start mode) Conversion started by an external trigger (hardware start mode)
CS 0 1
A/D converter operation control Stop operation Start operation
Notes 1. Set the A/D conversion time to at least 19.1 s. 2. Setting is prohibited because the A/D conversion time is less than 19.1 s. Cautions 1. Set bit 0 to 1. 2. When executing the HALT or STOP instruction, clear bit 7 (CS) of the ADM register to stop A/D conversion operations prior to the instruction execution. This reduces the total power consumption of the device in the standby mode, because the A/D converter consumes much power when operating. 3. To restart A/D conversion operation, clear the interrupt request flag (ADIF) to 0. Remark fX: Main system clock oscillation frequency 216
CHAPTER 9 A/D CONVERTER APPLICATION
*
Figure 9-2. Format of the A/D Converter Mode Register (PD780228 Subseries)
Symbol ADM0 7 CS0 6 0 5 FR02 4 FR01 3 FR00 2 0 1 0 0 0 Address FF80H At reset 00H R/W R/W
FR02
FR01
FR00
A/D conversion time selectionNote 1 With fX = 5.0 MHz With fX = 4.19 MHz 144/fX (34.4 s) 120/fX (28.6 s) 96/fX (22.9 s) 72/fX (17.2 s)
Note 2 Note 2
0 0 0 1 1 1
0 0 1 0 0 1
0 1 0 0 1 0
144/fX (28.8 s) 120/fX (24 s) 96/fX (19.2 s) 72/fX (14.4 s) 60/fX (Setting prohibited 48/fX (Setting prohibited Setting prohibited ) )
60/fX (14.3 s) 48/fX (Setting prohibitedNote 2)
Other than the above
CS0 0 1
A/D converter operation control Stop converter operation Enable converter operation
Notes 1. Set the A/D conversion time to at least 14 s. 2. Setting is prohibited because the A/D conversion time is less than 14 s. Caution The results of conversion obtained immediately after setting bit 7 (CS0) to 1 will be unpredictable. Remark fX: Oscillation frequency of the main system clock
217
78K/0 SERIES APPLICATION NOTE
Figure 9-3.
Format of the A/D Converter Input Selection Register (PD78044F, PD78044H, and PD780208 Subseries)
6 0 5 0 4 0 3 2 1 0 Address FF84H At reset 00H R/W R/W
Symbol ADIS
7 0
ADIS3 ADIS2 ADIS1 ADIS0
Selection of the number ADIS3 ADIS2 ADIS1 ADIS0 of analog input channels 0 0 0 0 No analog input channels (P10-P17) 0 0 0 1 1 channel (ANI0, P11-P17) 0 0 1 0 2 channels (ANI0, ANI1, P12-P17) 0 0 1 1 3 channels (ANI0-ANI2, P13-P17) 0 1 0 0 4 channels (ANI0-ANI3, P14-P17) 0 1 0 1 5 channels (ANI0-ANI4, P15-P17) 0 1 1 0 6 channels (ANI0-ANI5, P16, P17) 0 1 1 1 7 channels (ANI0-ANI6, P17) 1 0 0 0 8 channels (ANI0-ANI7) Other than the above Setting prohibited
Cautions 1. Set the analog input channel in the following order. <1> Set the number of analog input channels in ADIS. <2> For channels set for analog input in ADIS, the channel for A/D conversion selects one channel in the A/D converter mode register (ADM). 2. Regardless of the value of bit 1 (PUO1) in the pull-up resistor option register (PUO), the channel selected for analog input in ADIS does not use the on-chip pull-up resistor.
218
CHAPTER 9 A/D CONVERTER APPLICATION
*
Figure 9-4.
Format of the Analog Input Channel Specification Register (Only for the PD780228 Subseries)
7 0 6 0 5 0 4 0 3 2 1 0 Address FF81H At reset 00H R/W R/W
Symbol ADS0
ADS03 ADS02 ADS01 ADS00
ADS03 ADS02 ADS01 ADS00 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1
Analog input channel selection ANI0 ANI1 ANI2 ANI3 ANI4 ANI5 ANI6 ANI7 Setting prohibited
Other than the above
219
78K/0 SERIES APPLICATION NOTE
9.1 LEVEL METER The analog voltage input to the A/D converter is displayed by 16 LEDs. The LED display is arranged in a 4 x 4 matrix. An example using the PD78044F subseries is described here. Because the objective in this example is a level meter, this LED display digitally shows the current decibel level of the analog ANIn pin input. Figure 9-5 shows the level meter circuit. Figure 9-6 shows the relationship between the A/D conversion result and the number of display digits. Figure 9-5. Level Meter Circuit Example
PD78044F
P30 P31 P32 P33
ANIn
P34 P35 P36 P37
Figure 9-6. A/D Conversion Result and LED Display
LED (number) 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0AH 12H 20H 2EH 39H 40H 48H 51H 5BH 66H 72H 80H 90H A2H B5H FFH -22 -17 -12 -9 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 6 Display value [dB]
220
Display level
CHAPTER 9 A/D CONVERTER APPLICATION
The level meter in this example operates in the manner described in <1> to <3>. <1> Measurement method A/D conversion is performed every 20 ms. The data of the last four conversions are averaged and used in the LED display data. <2> Display method The LED is updated every 20 ms. The LED display is a 4 x 4 = 16 dynamic display. 8-bit timer/ event counter 1 (interval time: 2 ms) is used in the dynamic display. <3> Peak hold The maximum display level hold during a constant period (1 second) is called the peak hold. Even when the display level drops during the constant period, only the maximum display level of the LEDs is held. As a result, the hold period of the hold level ranges from 20 ms to 1 s. Figure 9-7. Conceptual Diagram of the Peak Hold
Constant period (1 s) Hold level Display level 6 6 6 5 6 4 6 5 7 7 8 8 9 9 9 8 9 7 9 6 9 5 9 5 4 4 4 3 4 3 5 5 6 6 6 2
(1) Package description LEVEL : Name of LED display subroutine DSPLEV : Display level storage area HLDLEV : Hold level storage area CT20MS : 20-ms measurement counter CT1S : 1-s measurement counter AX, HL, BC (subroutine servicing) Bank 0: A, HL, B (interrupt servicing)
221
78K/0 SERIES APPLICATION NOTE

Name ADDAT DSPLEV HLDLEV CT20MS CT1S DIGCNT DSPDAT WORKCT Use A/D conversion value storage Display level storage Hold level storage 20-ms measurement counter 1-s measurement counter Display digit counter Display data storage Work counter for loop operation 4 1 Attributes SADDR Bytes 4 1

Name T20MSF T1SF Set every 20 ms. Set every 1 s. Use
2 levels, 5 bytes * A/D converter * 8-bit timer/event counter 1 * P3 * Channel selection and operation start of the A/D converter * 2-ms interval for the 8-bit timer/event counter 1
ADM=#1000xxx1B TCL1=#10101010B TMC1=#00000001B CR10=130
* P3 output mode * Set the P3 output latch to the low level. * INTTM1 interrupt enabled
222
CHAPTER 9 A/D CONVERTER APPLICATION
This program is divided into the two parts of A/D conversion processing (subroutine) and LED display processing (interrupts). * A/D conversion processing Call LEVEL at least once every 20 ms from the main processing. In LEVEL processing, A/D conversion is performed when 20 ms have elapsed. * LED display The 4 x 4 matrix LED display performs a dynamic display by using interrupt servicing by 8-bit timer/event counter 1 (interval: 2 ms). In addition, in interrupt servicing by 8-bit timer/event counter 1, the flags of T20MSF (read in A/D conversion value) and T1SF (end of the hold period) used in A/D conversion are set using the interval (2 ms). (2) Use example EXTRN MOV MOV MOV CLR1 LEVEL,CT20MS,CT1S CT20MS,#10 CT1S,#50 TMC2,#00100110B TMMK3 ; Turn off LED display ; ANI0 pin, start operation ; Set 8-bit timer/event counter 1 to 2 ms.
P3=#00H PM3=#00000000B ADM=#10000001B TCL1=#10101010B CR10=#130 TMC1=#00000001B CLR1 TMMK1 EI
; Enable 8-bit timer/event counter 1 interrupt.
223
78K/0 SERIES APPLICATION NOTE
(3) SPD chart
LEVEL
IF : 20 ms has elapsed (T20MSF = 1) THEN Clear T20MSF Store the A/D conversion value in memory Average the A/D conversion values of the last four conversions (FOR : WORKCT = #0 ; WORKCT < #16 ; WORKCT++) IF : conversion result > comparison data for the display level THEN Update the comparison data ELSE BREAK Save the display data in memory IF : less than 1 second (T1SF = 0) THEN IF : hold level < display level THEN Set the display level to the hold level ELSE Clear T1SF Set the display level in the hold level Convert the display level and hold level into the segment signal Combine the digit signal and segment signal and store in memory
INTTM1
Select register bank 0 Output the OFF signal to digit and segment Output the memory contents indicating the digit counter Increment the digit counter Decrement the 20-ms measurement counter IF : 20 ms has elapsed (CT20MS = 0) THEN Set the 20-ms counter to 10 Set to the 20-ms elapsed state Set T20MSF Decrement the 1-s measurement counter IF : 1 second has elapsed (CT1S = 0) THEN Set 50 in the 1-s counter Set to the 1-s elapsed state Set T1SF
224
CHAPTER 9 A/D CONVERTER APPLICATION
(4) Program listing PUBLIC AD_DAT ADDAT: DSPLEV: HLDLEV: CT20MS: CT1S: DIGCNT: DSPDAT: WORKCT: AD_FLG T20MSF T1SF VETM1 DSEG DS DS DS DS DS DS DS DS BSEG DBIT DBIT CSEG DW AT 16H INTTM1 LEVEL,HLDLEV,DSPLEV,CT20MS,CT1S SADDR 4 1 1 1 1 1 4 1 ; ; ; ; ; ; ; A/D conversion result storage area Display level value Hold level value 20-ms measurement counter 1-s measurement counter Display digit counter Display data
; 20-ms measurement ; 1-s measurement ; Set vector address of 8-bit timer/event counter 1
AD_SEG CSEG ;********************************* ;* Level meter data setting ;********************************* LEVEL: IF_BIT(T20MSF) CLR1 T20MSF A=ADCR A<->ADDAT A<->ADDAT+1 A<->ADDAT+2 A<->ADDAT+3
; 20-ms check ; A/D conversion input ; Save A/D conversion value.
; Average the last four A/D conversion values. AX=#0H HL=#ADDAT ; Data storage address for(WORKCT=#0;WORKCT<#4;WORKCT++) A+=[HL] HL++ if_bit(CY) ; Carry X++ ; High-order digit endif next A<->X C=#4 AX/=C if(C>=#2) (A) X++ endif ; ; ; ; Average four conversions AX/C=AX (quotient)...C (remainder) Remainder processing (carry 2) Carry processing
HL=#LEVTBL B=#0 ; Conversion result storage register for(WORKCT=#0;WORKCT<#16;WORKCT++) if(X>=[HL+B]) (A) ; Data comparison B++ else break endif next 225
78K/0 SERIES APPLICATION NOTE
DSPLEV=B (A) if_bit(!T1SF) X=HLDLEV (A) if(XX A|=[HL+C] A<->X C++ A|=[HL+C] BC=AX HL=#DSPDAT A=C A&=#0FH A|=#00010000B [HL]=A HL++ A=C A>>=1 A>>=1 A>>=1 A>>=1 A&=#0FH A|=#00100000B [HL]=A HL++ A=B A&=#0FH A|=#01000000B [HL]=A HL++ A=B A>>=1 A>>=1 A>>=1 A>>=1 A&=#0FH A|=#10000000B [HL]=A endif 226
; Display data decision ; 1 s (hold update) ; Comparison of hold and display levels
; Create display level.
; Create hold level.
; First digit segment signal setting
; Digit signal setting
; Second digit segment signal setting
; Digit signal setting
; Third digit segment signal setting ; Digit signal setting
; Fourth digit segment signal setting
; Digit signal setting
CHAPTER 9 A/D CONVERTER APPLICATION
RET LEVTBL: DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DSPTBL: DW DW DW DW DW DW DW DW DW DW DW DW DW DW DW DW DW HLDTBL: DW DW DW DW DW DW DW DW DW DW DW DW DW DW DW DW DW $EJECT 0000000000000000B 0000000000000001B 0000000000000010B 0000000000000100B 0000000000001000B 0000000000010000B 0000000000100000B 0000000001000000B 0000000010000000B 0000000100000000B 0000001000000000B 0000010000000000B 0000100000000000B 0001000000000000B 0010000000000000B 0100000000000000B 1000000000000000B 0000000000000000B 0000000000000001B 0000000000000011B 0000000000000111B 0000000000001111B 0000000000011111B 0000000000111111B 0000000001111111B 0000000011111111B 0000000111111111B 0000001111111111B 0000011111111111B 0000111111111111B 0001111111111111B 0011111111111111B 0111111111111111B 1111111111111111B 0AH 12H 20H 2EH 39H 40H 48H 51H 5BH 66H 72H 80H 90H 0A2H 0B5H 0FFH
227
78K/0 SERIES APPLICATION NOTE
;************************************ ;* Level meter output ;************************************ TM1_SEG CSEG INTTM1: SEL RB0 P3=#00000000B ; Turn off digit and segment signals. HL=#DSPDAT B=DIGCNT (A) P3=[HL+B] (A) DIGCNT++ DIGCNT&=#00000011B CT20MS-; 20 ms ? if(CT20MS==#0) CT20MS=#10 ; Initial counter setting SET1 T20MSF CT1S-;1s? if(CT1S==#0) CT1S=#50 ; Initial counter setting SET1 T1SF endif endif RETI
228
CHAPTER 9 A/D CONVERTER APPLICATION
9.2 THERMOMETER In this example, a thermistor (6 k/0 C) is used in a temperature sensor and measures temperatures between -20 C and +50 C. Changes in resistance corresponding to the temperature of the thermistor can be represented in the following way. R = R0exp {B (1/T-1/T0 ) } R: T: R0 : T0 : B: Resistance at some temperature T [K] Any temperature [K] Resistance at the reference temperature T 0 [K] Reference temperature [K] Constant determined from the reference temperature T 0 [K] and T 0 [K]
However, the B constant is not constant and is changed by the temperature. The B constant is transformed in the above equation and can be determined by the following equation. 1 In (1/T-1/T0 ) R R0
B=
An example circuit is shown in Figure 9-8. This circuit is set so that 0 V is input at -20 C and 5 V are input at +50 C. Figure 9-8. Thermometer Circuit Example
Th
PD78044F
ANIn
229
78K/0 SERIES APPLICATION NOTE
In this example circuit, because the thermistor characteristics are not linear, the input analog voltage is changed into a temperature from -20 C to +50 C by comparing the voltage with table data and not by a calculation. This conversion result is saved in the RAM (DSPDAT) as two BCD digits. Figure 9-9 shows the thermistor characteristics. Table 9-1 shows the relationship between the temperature and the A/D conversion value. Also, the measurement method changes the average of the four conversion results into a temperature. Therefore, the conversion result is stored in the display area. Consequently, one datum in four is updated. For example, when measurement processing is performed every 250 ms, the display update period becomes one second. Figure 9-9. Temperature and Output Characteristics
(%) 100 90 Output characteristics percentage 80 70 60 50 40 30 20 10 0 -20
-10
0
10
20 Temperature
30
40
50 (C)
230
CHAPTER 9 A/D CONVERTER APPLICATION
Table 9-1. A/D Conversion Values and Temperatures
Conversion value 00 01 04 07 0A 0C 0F 12 16 19 1C 1F 23 26 2A 2D 31 35 Temperature [C] -20.0 -19.5 -18.5 -17.5 -16.5 -15.5 -14.5 -13.5 -12.5 -11.5 -10.5 -9.5 -8.5 -7.5 -6.5 -5.5 -4.5 -3.5 Conversion value 38 3C 40 44 48 4C 50 54 58 5C 60 64 69 6D 71 75 7A 7E Temperature [C] -2.5 -1.5 -0.5 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 13.5 14.5 Conversion value 82 86 8B 8F 93 97 9B 9F A3 A8 AC B0 B4 B7 BB BF C3 C7 Temperature [C] 15.5 16.5 17.5 18.5 19.5 20.5 21.5 22.5 23.5 24.5 25.5 26.5 27.5 28.5 29.5 30.5 31.5 32.5 Conversion value CB CE D2 D6 D9 DC E0 E3 E7 EA ED F0 F3 F6 F9 FC FE FF Temperature [C] 33.5 34.5 35.5 36.5 37.5 38.5 39.5 40.5 41.5 42.5 43.5 44.5 45.5 46.5 47.5 48.5 49.5 50.0
(1) Package description THMETER : Name of the thermometer subroutine DSPDAT : Display data storage area CNTPRO : Number of inputs test counter MINUSF : Minus temperature display flag T250MSF : Flag for setting 250 ms AX, BC, HL
231
78K/0 SERIES APPLICATION NOTE

Name ADDAT DSPDAT CNTPRO WORKCT Use A/D conversion value storage Display data storage Number of inputs test counter Work counter for loop operation Attributes SADDR Bytes 4 2 1

Name T250MSF MINUSF Use When set, measurement processing is executed. Set when the temperature is minus.
1 level, 2 bytes A/D converter Channel selection and operation start for A/D converter ADM=#1000xxx1B In timer processing, set the T250MSF flag in each measurement period. Then, call THMETER at least once during the measurement period.
232
CHAPTER 9 A/D CONVERTER APPLICATION
(2) Use example EXTRN EXTBIT AD_DAT DSEG CT250MS:DS LEDD: DS DIGCT: DS VETM3 CSEG DW THMETER,DSPDAT,CNTPRO MINUSF,T250MSF SADDR 1 4 1 AT 12H INTTM3
; 250-ms measurement counter ; LED display area ; LED display digit counter
; Vector address setting of the watch timer ; 1.95-ms setting for the watch timer
MOV TMC2,#00100110B CLR1 TMMK3 : : CT250MS=#128 CNTPRO=#4 ADM=#10000011B : :
; ANI1 pin, operation start
;************************************** ; Watch timer interrupt servicing ; 1.95-ms interval ;************************************** INTTM3: ; 1.95-ms interrupt servicing : : DBNZ CT250MS,$RTNTM3 MOV CT250MS,#128 ; 250-ms had elapsed SET1 T250MSF RTNTM3: : : RETI
233
78K/0 SERIES APPLICATION NOTE
(3) SPD chart
THMETER
IF : 250 ms has elapsed (T250MS = 1) THEN Clear T250MS Save the A/D conversion value in memory IF : 4 conversions are saved in memory THEN Average four A/D conversion values (FOR : WORKCT = #0 ; WORKCT < #70 ; WORKCT++) IF : conversion result > comparison data for temperature conversion THEN Update comparision data ELSE BREAK IF : Temperature data is a negative value THEN Set in the minus state Set MINUSF Convert the temperature data into a decimal number and save in memory
234
CHAPTER 9 A/D CONVERTER APPLICATION
(4) Program listing PUBLIC AD_DAT ADDAT: DSPDAT: CNTPRO: WORKCT: DSEG DS DS DS DS THMETER,DSPDAT,CNTPRO,T250MSF,MINUSF SADDR 4 2 1 1 ; A/D conversion result storage area ; Display data ; Test the number of inputs.
AD_FLG BSEG T250MSF DBIT MINUSF DBIT TH_SEG CSEG ;******************************** ;* Temperature data setting ;******************************** THMETER: if_bit(T250MSF) CLR1 T250MSF A=ADCR A<->ADDAT A<->ADDAT+1 A<->ADDAT+2 A<->ADDAT+3
; 250-ms setting ; Negative data setting
; 250 ms
CNTPRO-if(CNTPRO==#0) CNTPRO=#4 AX=#0H HL=#ADDAT ; Data storage address for(WORKCT=#0;WORKCT<#4;WORKCT++) A+=[HL] HL++ if_bit(CY) ; Carry present. X++ ; Carry endif next A<->X C=#4 AX/=C if(C>=#2) (A) X++ endif
; AX/C=AX (quotient)...C (remainder) ; Remainder processing (carry 2) ; Carry processing
A=X ; Convert to temperature data. B=#0 HL=#THRTBL if(A==#0FFH) B=#70 else for(WORKCT=#0;WORKCT<#70;WORKCT++) if(X>=[HL+B]) (A) B++ else break endif next 235
78K/0 SERIES APPLICATION NOTE
endif CLR1 MINUSF A=#20 B-=A if_bit(CY) SET1 MINUSF A=#0 A-=B A<->B endif X=#0 A=B A<->X C=#10 AX/=C DSPDAT=C (A) (DSPDAT+1)=X (A) endif endif RET
; Temperature data 20 ; To decimal conversion
; Take the absolute value of data
; Decimal conversion
; Temperature data/10 ; Update display data.
236
CHAPTER 9 A/D CONVERTER APPLICATION
THRTBL: ; DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB 1 4 7 0AH 0CH 0FH 12H 16H 19H 1CH 1FH 23H 26H 2AH 2DH 31H 35H 38H 3CH 40H 44H 48H 4CH 50H 54H 58H 5CH 60H 64H 69H 6DH 71H 75H 7AH 7EH 82H 86H 8BH 8FH 93H 97H 9BH 9FH 0A3H 0A8H 0ACH 0B0H 0B4H 0B7H 0BBH 0BFH 0C3H 0C7H 0CBH 0CEH 0D2H 0D6H ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; -19.5 -18.5 -17.5 -16.5 -15.5 -14.5 -13.5 -12.5 -11.5 -10.5 -9.5 -8.5 -7.5 -6.5 -5.5 -4.5 -3.5 -2.5 -1.5 -0.5 +0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 13.5 14.5 15.5 16.5 17.5 18.5 19.5 20.5 21.5 22.5 23.5 24.5 25.5 26.5 27.5 28.5 29.5 30.5 31.5 32.5 33.5 34.5 35.5 36.5
237
78K/0 SERIES APPLICATION NOTE
DB DB DB DB DB DB DB DB DB DB DB DB DB
0D9H 0DCH 0E0H 0E3H 0E7H 0EAH 0EDH 0F0H 0F3H 0F6H 0F9H 0FCH 0FEH
; ; ; ; ; ; ; ; ; ; ; ; ;
37.5 38.5 39.5 40.5 41.5 42.5 43.5 44.5 45.5 46.5 47.5 48.5 49.5
238
CHAPTER 9 A/D CONVERTER APPLICATION
9.3 ANALOG KEY INPUT The A/D converter is used to read in 16 keys. In order to perform key input, the circuit is configured so that when a key is pressed, a voltage unique to that key is input into the A/D converter. In this example, because 16 different keys are read in, the VDD voltage is divided into 16 levels. This voltage is converted into a key code. Table 9-2 shows the relationship between the input voltage and key code (00H-0FH). When there is no key input, the key code is 10H. Table 9-2. Input Voltages and Key Codes
Input voltage (V) GND 1/16VDD 2/16VDD 3/16VDD 4/16VDD 5/16VDD 6/16VDD 7/16VDD 8/16VDD 9/16VDD 10/16VDD 11/16VDD 12/16VDD 13/16VDD 14/16VDD 15/16VDD VDD A/D conversion value 00-07H 08-17H 18-27H 28-37H 38-47H 48-57H 58-67H 68-77H 78-87H 88-97H 98-A7H A8-B7H B8-C7H C8-D7H D8-E7H E8-F7H F8-FFH Key code 00H 01H 02H 03H 04H 05H 06H 07H 08H 09H 0AH 0BH 0CH 0DH 0EH 0FH 10H
Figure 9-10 shows an example circuit implementing the relationship between the input voltage and the key code. However, when two or more keys are pressed in this circuit, the key having the smaller code is given priority and read in.
239
78K/0 SERIES APPLICATION NOTE
Figure 9-10. Analog Key Input Circuit Example
VDD R0 ANIn K1 R1
K0
K2
R2
PD78044F
K14
R14
R15 K15
Resistors R0 to R15 used in the circuit shown in Figure 9-10 can be determined from the following equation.
n
K=1
RK =
n x R0 16 - n
Table 9-3 shows the resistances of R1 to R15 based on this equation when R0 was 1 k. (Because the resistances are based on the color-coded display on commercial resistors, the calculation results may differ.) Table 9-3. Resistances of R1 to R15
Resistor number R1 R2 R3 R4 R5 Resistance () 68 75 82 100 120 Resistor number R6 R7 R8 R9 R10 Resistance () 150 180 220 270 390 Resistor number R11 R12 R13 R14 R15 Resistance () 560 750 1.3 k 2.7 k 8.2 k
In this program, the analog voltage that was input is converted into a key code listed in Table 9-2. After chattering is absorbed, the code is saved in RAM. Chattering absorption uses a technique where a key becomes valid when the key code matches five consecutive times. For example, when sampling is performed every 5 ms, chattering lasting 20 ms to 25 ms is absorbed. When the key input changed, the key change flag (KEYCHG) is set.
240
CHAPTER 9 A/D CONVERTER APPLICATION
(1) Package description AKEYIN : Name of analog key input subroutine KEYDAT : Key code storage area PASTDT : Key code storage area for chattering absorption CHATCT : Chattering absorption counter KEYCHG : Key change test flag CHTENDF : End of chattering absorption test flag KEYOFF : Key code when there is no key input A
Name PASTDAT KEYDAT CHATCNT Use Key code storage for chattering absorption Key code storage Chattering counter Attributes SADDR Bytes 1

Name KEYCHG CHTENDF Set when the key changes Set at the end of chattering absorption Use
1 level, 2 bytes A/D converter Channel selection and operation start of A/D converter ADM=#1000xxx1B * Call AKEYIN in each constant interval. * Read in the key code after testing the key change flag. Also, because the key change flag is not cleared in the subroutine, clear after testing the flag.
241
78K/0 SERIES APPLICATION NOTE
(2) Use example EXTRN EXTRN EXTBIT VETM3 CSEG DW AKEYIN,KEYDAT,PASTDT,CHATCT KEYOFF KEYCHG,CHTENDF AT 12H INTTM3 SADDR 1
; Vector address setting of the watch timer
MAINDAT DSEG CT5MS: DS
TMC2=#00100110B CLR1 TMMK3 CT5MS=#3 KEYDAT=#KEYOFF PASTDT=#KEYOFF CHATCT=#CHAVAL CLR1 CHTENDF CLR1 KEYCHG ADM=#10000101B EI : : if_bit(KEYCHG) CLR1 KEYCHG ; Key input processing endif : : ; Set the OFF data in the key data. ; Set the chattering count to 5 times.
; ANI2 pin, operation start
; Did the key change?
;*************************************** ; Watch timer interrupt servicing ; 1.95-ms interval ;*************************************** INTTM3: ; 1.95-ms interrupt servicing : : DBNZ CT5MS,$RTNTM3 MOV CT5MS,#3 ; 1.95 ms x 3 elapsed CALL !AKEYIN RTNTM3: : : RETI
242
CHAPTER 9 A/D CONVERTER APPLICATION
(3) SPD chart
AKEYIN
Adjust and input of A/D conversion value (add 8) IF : There is an overflow THEN Set to the state where there is no input key ELSE Decode key IF : There is no key input change THEN IF : Absorbing chattering THEN IF : Chattering absorption finished THEN Set to the chattering absorption state Set CHTENDF IF : There is a change to a valid key THEN Update key code Set to key change state ELSE Set KEYCHG Update the comparison key code Set to the start chattering absorption state Clear CHTENDF
243
78K/0 SERIES APPLICATION NOTE
(4) Program listing PUBLIC PUBLIC PUBLIC AK_DAT DSEG KEYDAT: DS PASTDT: DS CHATCT: DS AK_FLG BSEG KEYCHG DBIT CHTENDF DBIT KEYOFF CHAVAL EQU EQU 10H 5 AKEYIN,KEYDAT,PASTDT CHATCT,KEYOFF KEYCHG,CHTENDF SADDR 1 1 1
; Key data storage area ; Chattering key data ; Chattering counter
; Key change. ; End of chattering absorption state ; OFF key data ; Chattering absorption count
AK_SEG CSEG ;************************** ;* Analog key input ;************************** AKEYIN: A=ADCR A+=#8 if_bit(CY) A=#KEYOFF else A>>=1 A>>=1 A>>=1 A>>=1 A&=#0FH endif if(A==PASTDT) if_bit(!CHTENDF) CHATCT-if(CHATCT==#0) SET1 CHTENDF A=PASTDT if(A!=KEYDAT) KEYDAT=A SET1 KEYCHG endif endif endif else PASTDT=A CHATCT=#CHAVAL-1 CLR1 CHTENDF endif RET
; A/D conversion input ; Data adjustment ; Set to the no input key state. ; Decode key
; No key change ; Absorbing chattering ; End of chattering absorption ; Set to the end of chattering absorption state ; There is a valid key change. ; Update key data. ; Set to the key change state.
; Update previous key data. ; Start chattering absorption.
244
CHAPTER 9 A/D CONVERTER APPLICATION
9.4 4-CHANNEL INPUT A/D CONVERSION This section describes an A/D conversion method where four channels are scanned. A/D conversion is started by a software start. Analog voltages input to the four selected channels undergo A/D conversion. The conversion result of each channel is saved in RAM. An interrupt request is generated by 8-bit timer/event counter 1 and the conversion result is read into processing for the interrupt request and channel conversion is performed. Because the time set for 8-bit timer/event counter 1 is 10 ms, measuring the waiting time for A/D conversion is not necessary. Caution When the interrupt time changes, set the following. * The timer is set to a value longer than A/D-conversion-completion-time + interrupt-return-time + interrupt-servicing-time
* Flags are tested at the end of conversion. Figure 9-11. Timing Chart in the 4-Channel Scanning Mode
INTTM2
10 ms
ADCR
ANI0
ANI1
ANI2
ANI3
ANI0
ANI1
ANI2
ANI3
ANI0
ADIn
0
1
2
3
0
1
2
3
0
1
(1) Package description conversion conversion conversion conversion result result result result of of of of channel channel channel channel 0 1 2 3
245
78K/0 SERIES APPLICATION NOTE
A
Name M_CH0 M_CH1 M_CH2 M_CH3 M_MODE Use Storage area for channel 0 conversion result Storage area for channel 1 conversion result Storage area for channel 2 conversion result Storage area for channel 3 conversion result Mode storage area Attributes SADDR SADDR SADDR SADDR SADDR Bytes 1 1 1 1 1
1 level, 3 bytes * A/D converter * 8-bit timer/event counter 1 * Port 1 (P10-P13) * Channel selection and operation start of the A/D converter * Channel number selection of A/D converter * 10-ms interval for 8-bit timer/event counter 1
ADM=#1000xxxxB ADIS=#00000100B TCL1=#00001101B TMC1=#00000001B CR10=#81
* TMMK1 interrupt enabled
246
CHAPTER 9 A/D CONVERTER APPLICATION
(2) Use example EXTRN M_CH0,M_CH1,M_CH2,M_CH3,M_MODE ;************************************** ; Initialize ;************************************** M4 CSEG ; RES_STA: SEL RB0 ; DI ; . . ADM=#10000001B ; A/D operation start, no external trigger, channel 0 selected ADIS=#00000100B ; Analog input, 4 channels selected CR10=#81 ; Modulo register 81 setting TCL1=#00001101B ; Count/clock 8.2 kHz TMC1=#00000001B ; Enable 8 bit/timer/register 1 operation CLR1 TMIF1 ; Clear timer 1 interrupt request flag. CLR1 TMMK1 ; Enable timer 1 interrupt. EI ; M_MODE=#0 ; Set the initial value (0 channels) in the mode area . . while(forever) ; . . A=M_CH0 ; A <- channel 0 data . . A=M_CH1 ; A <- channel 1 data . . A=M_CH2 ; A <- channel 2 data . . A=M_CH3 ; A <- channel 3 data . . (3) SPD chart [A/D conversion processing]
KASAN
Read in the conversion result of the channel in the previous A/D conversion Change the channel ADM<-Changed channel selection
247
78K/0 SERIES APPLICATION NOTE
(4) Program listing ; ;************************************** ; A/D conversion ;************************************** ; $PC(044A) ; PUBLIC M_CH0,M_CH1,M_CH2,M_CH3,M_MODE ; VEINTM1 CSEG AT 16H DW KASAN ;************************************** ; RAM definition ;************************************** DSEG SADDR M_CH0: DS 1 M_CH1: DS 1 M_CH2: DS 1 M_CH3: DS 1 M_MODE: DS 1 ; CSEG KASAN: SEL RB2 switch(M_MODE) case 0: M_CH0=ADCR (A) M_MODE++ ADM=#10000011B break case 1: M_CH1=ADCR (A) M_MODE++ ADM=#10000101B break case 2: M_CH2=ADCR (A) M_MODE++ ADM=#10000111B break case 3: M_CH3=ADCR (A) M_MODE=#0 ADM=#10000001B break ends RETI END
; ;
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
RAM area for channel RAM area for channel RAM area for channel RAM area for channel Mode storage area
0 1 2 3
addition addition addition addition
Switch to bank 2. Which channel is currently selected? Channel 0: Transfer conversion result to RAM Change channel selection to 1. Channel 1: Transfer conversion result to RAM Change channel selection to 2. Channel 2: Transfer conversion result to RAM Change channel selection to 3. Channel 3: Transfer conversion result to RAM Change channel selection to 0.
248
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER
The functions of the FIP controller/driver are listed below. The differences between the PD78044F, PD78044H, PD780208, and PD780228 subseries are listed in Table 10-1. (1) Segment signal output (DMA operation) by automatically reading display data and automatic output of digit signals (2) Display mode register controlling FIP (fluorescent indicator panel) (See Table 10-1.) (3) Those pins not used for FIP display can be used either as output port or I/O port pins (however, pins FIP0 through FIP12 of the PD780208 subseries and pins FIP0 through FIP15 of the PD780228 subseries are dedicated to display output). (4) Brightness can be set to one of eight steps by using display mode register 1 (DSPM1). (5) Hardware for key scan application * Generates an interrupt request signal (INTKS) indicating the key scan timing * Key scan signals are output from segment output pins if data for key scanning is set to port (see Table 10-1). * Key scan data output timing can be detected by key scan flag (KSF). * Whether the key scan timing is inserted can be selected (only for the PD780228 subseries). (6) High-voltage output buffer directly driving FIP (7) Pull-down resistor can be connected by mask option to display output pins. (8) Any digit signal output timing can be set by selecting display mode 2 with display mode register 0 (DSPM0) (PD780208 subseries only). Caution The format of the registers incorporated into the PD780228 subseries differs from that of the registers incorporated into the PD78044F, PD78044H, and PD780208 subseries. When using any of the sample programs described in this chapter with the PD780228 subseries, replace the register settings with those for the PD780228 subseries.
*
*
*
249
78K/0 SERIES APPLICATION NOTE
*
Table 10-1. Differences between PD78044F, PD78044H, PD780208, and PD780228 Subseries
PD78044F subseries 9-24 2-16 PD78044H subseries 9-40 PD780208 subseries PD780228 subseries Up to 48 for total number of segments and digits
Subseries Item Number of segments Number of digits
Display mode
* Segment type
* Segment type * Character type * Type that a segment extends two or more grids Ports 8-12 Ports 7-10
Multiplexed key scan port Controlling register
Ports 11 and 12 Display mode registers 0 and 1 (DSPM0 and DSPM1)
Display mode registers 0-2 (DSPM0-DSPM2)
250
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER
Figure 10-1. Format of Display Mode Register 0 (PD78044F and PD78044H Subseries)
Symbol DSPM0
7
6
5 0
4 0
3
2
1
0
Address FFA0H
At reset 00H
R/W R/WNote 1
KSF DSPM06
SEGS3 SEGS2 SEGS1 SEGS0
SEGS3 SEGS2 SEGS1 SEGS0 Number of display segments 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
DSPM06 Mode setting for the noise eliminator of the
subsystem clockNote 2 0 1 KSF 0 1 2.5 MHz < fX < 5.0 MHz 1.25 MHz < fX < 2.5 MHz Timing status Display timing Key scan timing
Notes 1. Bit 7 (KSF) is read-only. 2. Specify a value in accordance with the oscillation frequency of the main system clock (fX). The noise eliminator can be used during FIP display operation. Caution When using the FIP controller/driver with a main system clock of 1.25 MHz, use the main system clock (TCL24 (bit 4 of timer clock selection register 2 (TCL2)) = 0) for the watch timer. Remark fX: Oscillation frequency of the main system clock
251
78K/0 SERIES APPLICATION NOTE
Figure 10-2. Format of Display Mode Register 0 (PD780208 Subseries) (1/2)
Symbol DSPM0
7
6
5
4
3
2
1
0
Address FFA0H
At reset 00H
R/W R/W
KSF DSPM06 DSPM05 SEGS4 SEGS3 SEGS2 SEGS1 SEGS0
R/W
SEGS4 SEGS3 SEGS2 SEGS1 SEGS0 Number of display segments (display mode 1) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38Note 39 40
Note Note
Number of display outputs (display mode 2) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
Note If the total number of digits and segments exceeds 53, digits have precedence over segments.
252
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER
Figure 10-2. Format of Display Mode Register 0 (PD780208 Subseries) (2/2)
Symbol DSPM0 7 6 5 4 3 2 1 0 Address FFA0H At reset 00H R/W R/WNote 1
KSF DSPM06 DSPM05 SEGS4 SEGS3 SEGS2 SEGS1 SEGS0
R/W
DSPM05 Setting of display mode
0 1
Display mode 1 (segment/character type) Display mode 2 (type that a segment extends two or more grids)
R/W
DSPM06 Mode setting for the noise eliminator of the subsystem clockNote 2
0 1
2.5 MHz < fX < 5.0 MHz 1.25 MHz < fX < 2.5 MHzNote 3
R
KSF 0 1
Timing status Display timing Key scan timing
Notes 1. Bit 7 (KSF) is read-only. 2. Specify a value in accordance with the oscillation frequency of the main system clock (fX). The noise eliminator can be used during FIP display operation. 3. When fX is used from above 1.25 MHz to 2.5 MHz, set 1 in DSPM06 before FIP display. Caution When using the FIP controller/driver with a main system clock of 1.25 MHz, use the main system clock (TCL24 (bit 4 of timer clock selection register 2 (TCL2)) = 0) for the watch timer. Remark fX: Oscillation frequency of the main system clock
253
78K/0 SERIES APPLICATION NOTE
*
Symbol
Figure 10-3. Format of Display Mode Register 0 (PD780228 Subseries)
7 6 0 5 4 3 2 1 0 Address FF90H At reset 10H R/W R/W
DSPM0 DSPEN
FOUT5 FOUT4 FOUT3 FOUT2 FOUT1 FOUT0
FOUT5 FOUT4 FOUT3 FOUT2 FOUT1 FOUT0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1
Number of FIP output pins 17-24 25-32 33-40 41-48 Setting prohibited
Other than the above
DSPEN 0 1
Enabling or disabling FIP display Enable FIP display Disable FIP display
Cautions 1. Always set bit 6 to 0. 2. When bit 7 (DSPEN) is 1, do not write data into bits other than DSPEN. 3. The output latch of the port multiplexed with the pins used for FIP output must be set to 0.
254
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER
Figure 10-4. Format of Display Mode Register 1 (PD78044F and PD78044H Subseries)
Symbol DSPM1 7 6 5 4 3 2 1 0 Address FFA1H At reset 00H R/W R/W
DIGS3 DIGS2 DIGS1 DIGS0 DIMS3 DIMS2 DIMS1 DIMS0
DIMS0 0 1
Display cycle selection 1024/fX as 1 display cycle (One display cycle is 204.8 s at 5.0 MHz.) 2048/fX as 1 display cycle (One display cycle is 409.6 s at 5.0 MHz.) Cut width of the digit signal 1/16 2/16 4/16 6/16 8/16 10/16 12/16 14/16 Number of display digits Disabled display (static display)Note 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
DIMS3 DIMS2 DIMS1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1
DIGS3 DIGS2 DIGS1 DIGS0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Note When display is disabled, a port output latch can be operated to enable static display. Remark fX: Oscillation frequency of the main system clock
255
78K/0 SERIES APPLICATION NOTE
Figure 10-5. Format of Display Mode Register 1 (PD780208 Subseries)
Symbol DSPM1
7
6
5
4
3
2
1
0
Address FFA1H
At reset 00H
R/W R/W
DIGS3 DIGS2 DIGS1 DIGS0 DIMS3 DIMS2 DIMS1 DIMS0
DIMS0 0 1
Setting of display mode cycle 1024/fX as 1 display cycle (One display cycle is 204.8 s at 5.0 MHz.) 2048/fX as 1 display cycle (One display cycle is 409.6 s at 5.0 MHz.) Cut width of the FIP output signal 1/16 2/16 4/16 6/16 8/16 10/16 12/16 14/16
DIMS3 DIMS2 DIMS1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1
DIGS3 DIGS2 DIGS1 DIGS0 Number of display digits (display mode 1) Number of display patterns (display mode 2) DSPM05 = 1 DSPM05 = 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 Disabled display (static display)Note 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Disabled display (static display)Note 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Note When display is disabled, a port output latch can be operated to enable static display. Remark fX : Oscillation frequency of the main system clock DSPM05 : Bit 5 of display mode register 0 256
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER
*
Symbol
Figure 10-6. Format of Display Mode Register 1 (PD780228 Subseries)
7 6 5 4 3 2 1 0 Address FF91H At reset 01H R/W R/W
DSPM1 FBLK2 FBLK1 FBLK0 FPAT4 FPAT3 FPAT2 FPAT1 FPAT0
FPAT4 FPAT3 FPAT2 FPAT1 FPAT0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Number of display patterns 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Setting prohibited
Other than the above
FBLK2 FBLK1 FBLK0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1
Blanking width for the FIP output signal 1/16 2/16 4/16 6/16 8/16 10/16 12/16 14/16
Caution When bit 7 (DSPEN) of display mode register 0 (DSPM0) is 1, do not write data into display mode register 1 (DSPM1).
257
78K/0 SERIES APPLICATION NOTE
Figure 10-7. Format of Display Mode Register 2 (PD780208 Subseries) (1/2)
Symbol DSPM2 7 0 6 0 5 4 3 2 1 0 Address FFA1H At reset 00H R/W R/W
USEG5 USEG4 USEG3 USEG2 USEG1 USEG0
USEG5 USEG4 USEG3 USEG2 USEG1 USEG0 Number of write mask bits 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 None 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
258
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER
Figure 10-7. Format of Display Mode Register 2 (PD780208 Subseries) (2/2)
Symbol DSPM2 7 0 6 0 5 4 3 2 1 0 Address FFA1H At reset 00H R/W R/W
USEG5 USEG4 USEG3 USEG2 USEG1 USEG0
USEG5 USEG4 USEG3 USEG2 USEG1 USEG0 Number of write mask bits 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 32 33 34 35 36 37 38 39 Setting prohibited
Other than the above
259
78K/0 SERIES APPLICATION NOTE
*
Symbol
Figure 10-8. Format of Display Mode Register 2 (PD780228 Subseries)
7 KSF 6 KSM 5 0 4 0 3 0 2 0 1 0 Address FF92H At reset 00H R/W R/W
DSPM2
FCYC1 FCYC0
FCYC1 FCYC0 0 0 1 1 0 1 0 1
Display cycle 212fX (819.2 s) 211/fX (409.6 s) 210/fX (204.8 s) Setting prohibited
KSM 0 1
Selection of key scan cycle insertion Insert a key scan cycle Insert no key scan cycle
KSF 0 1
Status of the key scan cycle During a cycle other than the key scan cycle During the key scan cycle
Cautions 1. Always set 0 in bits 2 to 5. 2. When bit 7 (DSPEN) of display mode register 0 (DSPM0) is 1, do not write data into display mode register 2 (DSPM2). Remarks 1. fX: Oscillation frequency of the main system clock 2. The values in parentheses apply to operation with fX = 5.0 MHz.
260
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER
Figure 10-9. FIP Controller Operation Timing
TCYT TDSP Digit signal FIP0 FIP1 TKS
FIP2
TDIG
FIPn
Key scan flag (KSF) Can be changed at any time Segment signal
1 display cycle
Key scan timing
: Number of display digits - 1 (2 to 16 digits selectable by display mode register 1 (DSPM1) TDSP : One display cycle (1024/fX (244 s at 4.19 MHz) or 2048/fX (488 s at 4.19 MHz)) TKS : Key scan timing (TKS = TDSP) TCYT : Display cycle (TCYT = TDSP x (number of digits + 1)) TDIG : Digit signal pulse width (eight types, selectable with display mode register 1 (DSPM1))
n
261
78K/0 SERIES APPLICATION NOTE
10.1 12-DIGIT DISPLAY FOR FIP AND KEY INPUT This section shows an example of processing an FIP having 12 digits by 9 segments and 8 x 4 key inputs by using the FIP controller/driver of the PD78044F subseries. In this example, a key of the 8 x 4 key matrix that has been pressed is displayed on the first digit of the FIP (TO in Figure 10-10), and the data that has already been displayed is shifted one column to the left. Figure 10-10 shows the configuration. Figure 10-10. Configuration of 12-Digit FIP Display and Key Input
PD78044F P80 P81 P90 P91 P92 P93 P94 P95 P96 P97 P100 P101 P102 P103 P104 P105 P106 P107 T11 S0 S1 S2 S3 S4 S5 S6 S7 S8 P110 P111 P112 P113 P114 P115 P116 P117 P120 P121 P122 P123 FIP display T10 T9 T8 T7 T6 T5 T4 T3 T2 T1 T0
=
262
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER
10.1.1 12-Digit FIP Display (1) Setting the number of segments and number of digits With the circuit shown in Figure 10-10, twelve digits are displayed using eight key scan signals. The 9 segment x 12 digit FIP display mode is set. Nine segments is the minimum value for the selected number. Figure 10-11 shows the pin layout according to the number of display digits for which nine segments are displayed.
263
78K/0 SERIES APPLICATION NOTE
Figure 10-11. Pin Layout for 9-Segment Display
Selected Number of Display Digits Pin Name
Display stops
2 T0 T1 P90 P91 P92 P93 P94 P95 P96 P97 S0 S1 S2 S3 S4 S5 S6 S7 S8P110 P111 P112 P113 P114 P115 P116 P117 P120 P121 P122 P123 P124 P125 P126 P127
*********
9 T0 T1 T2 T3 T4 T5 T6 T7 T8 P97 S0 S1 S2 S3 S4 S5
10 T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 S0 S1 S2 S3 S4 S5 S6 S7
11 T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 S0 S1 S2 S3 S4 S5 S6
12 T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 S0 S1 S2 S3 S4 S5
*********
16 T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15
FIP0/P80 FIP1/P81 FIP2/P90 FIP3/P91 FIP4/P92 FIP5/P93 FIP6/P94 FIP7/P95 FIP8/P96 FIP9/P97 FIP10/P100 FIP11/P101 FIP12/P102 FIP13/P103 FIP14/P104 FIP15/P105 FIP16/P106 FIP17/P107 FIP18/P110 FIP19/P111 FIP20/P112 FIP21/P113 FIP22/P114 FIP23/P115 FIP24/P116 FIP25/P117 FIP26/P120 FIP27/P121 FIP28/P122 FIP29/P123 FIP30/P124 FIP31/P125 FIP32/P126 FIP33/P127
P80 P81 P90 P91 P92 P93 P94 P95 P96 P97 P100 P101 P102 P103 P104 P105 P106 P107 P110 P111 P112 P113 P114 P115 P116 P117 P120 P121 P122 P123 P124 P125 P126 P127
*********
S6 S7
*********
S0 S1 S2P110 S3P111 S4P112 S5P113 S6P114 S7P115 S8P116 P117 P120 P121 P122 P123 P124 P125 P126 P127
S8P110 S8P110 S7P110 S6P110 P111 P112 P113 P114 P115 P116 P117 P120 P121 P122 P123 P124 P125 P126 P127 P111 P112 P113 P114 P115 P116 P117 P120 P121 P122 P123 P124 P125 P126 P127 S8P111 S7P111 P112 P113 P114 P115 P116 P117 P120 P121 P122 P123 P124 P125 P126 P127 S8P112 P113 P114 P115 P116 P117 P120 P121 P122 P123 P124 P125 P126 P127
: Logical add (OR) : Area used by this program
264
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER
(2) Display data memory The display data memory is an area that stores the segment data to be displayed on an FIP. This area is mapped to addresses FA50H through FA7FH. The FIP controller reads data from this area independently of instruction operation to enable the display of the FIP and outputs a segment signal synchronized with digit signals (DMA operation). Any unused portion of this area can be used as an ordinary RAM area. When a key is scanned, all digit signals are cleared to 0, and the data of the output latches of ports 11 and 12 are output to the FIP18/P110 through pins FIP33/P127. The shaded portion in Figure 10-12 indicates the area used by this program. Figure 10-12. Relationship between Contents of Display Data Memory and Segment Output
Bit 7 FA50H FA51H FA52H FA53H FA54H FA55H FA56H FA57H FA58H FA59H FA5AH FA5BH FA5CH FA5DH FA5EH FA5FH
07 FA60H FA61H FA62H FA63H FA64H FA65H FA66H FA67H FA68H FA69H FA6AH FA6BH FA6CH FA6DH FA6EH FA6FH
07 FA70H FA71H FA72H FA73H FA74H FA75H FA76H FA77H FA78H FA79H FA7AH FA7BH FA7CH FA7DH FA7EH FA7FH
0 T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15 TKS
Timing output
000000000000000000000000
S23
S16 S15
S8 S7
S0
265
78K/0 SERIES APPLICATION NOTE
(3) Display To display an FIP, output the data set for a display digit as the digit signals and write the data to be displayed as segment signals (i.e., to the display data memory). As an example, the setting of display mode registers 0 and 1 when 9 segments and 12 digits are to be displayed is shown below. Figure 10-13 shows an example display based on this setting.
* Setting of DSPM0 *
DSPM0 = #00000000B ; Selects 9 segments Setting of DSPM1 DSPM1 = #10110011B ; Selects 12 digits, a digit signal cut width of 2/16, and a display cycle of 488 s (at 4.19 MHz) Figure 10-13. Display Example
10.1.2 Key Input An example of a program that receives input from an 8 x 4 key matrix is shown. The circuit used for this program uses port 11 (P110 through P117) for the key scan signals and the lower 4 bits (P120 through P123) of port 12 for the key return signals (see Figure 10-10). The key scan flag (KSF) is set to 1 while keys are scanned and is cleared to 0 during display. When this flag is set to 1, an interrupt request occurs and keys are input by this interrupt. Because not all of the 8 x 4 keys can be input during the time made available by one interrupt request (488 s), the interrupt request must be issued twice to enable input of all the keys. The timing chart shown in Figure 10-14 illustrates how all the keys are input.
266
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER
Figure 10-14. Key Interrupt Timing Chart
FIP0 FIP1 488 s FIP11 KSF
High KEY1_NEW
Low
Reads first half of key data
Reads remainder of key data
KEY1_NEW +7
One input key corresponds to 1 bit and is stored in RAM. The RAM data is set according to the pressed key. When the key is released, the data is cleared. By sequentially testing each bit of RAM data starting from the first bit, therefore, the statuses of the keys can be checked. Chattering is compensated for by validating the key only if the key data coincides with the corresponding RAM bit three times in a row. Because 12 digits are displayed and the keys are scanned every 12.688 ms (= 13 x 488 s (display cycle selectable) x two times (number of interrupts necessary for inputting all the keys)) in this example, chattering of about 25 ms to 38 ms can be eliminated. If a key input is changed, the key change flag (F_KHENKA) is set. Figure 10-15 illustrates how chattering is eliminated.
267
78K/0 SERIES APPLICATION NOTE
Figure 10-15. Compensating for Chattering
KSF 12.688 ms 1st correspondence 2nd correspondence 3rd correspondence
To prevent unwanted data from being displayed during display, the timing is checked by the key scan flag (KSF) at the beginning and end of key scan processing. 10.1.3 Description of Package (1) FIP display An FIP display program is not included in the package. Refer to the explanation of initial setting and display data conversion processing in Section 10.1.4. (2) Key input Because key input processing is performed as interrupt processing, the key input processing performed by this package is executed when the INTKS interrupt request is enabled. * Output parameters KEY1_OLD : Stores key bit after eliminating chattering KEY1_NEW : Stores key bit while eliminating chattering SCAN : Stores scanned key data NEWKEYP : Stores RAM address used to store next key bit while eliminating chattering F_KHENKA : Set if current key is found to be different from previous key after eliminating chattering Bank 2, AX, HL, DE, B
268
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER

Name C_CAHTA KEY1_OLD KEY1_NEW SCAN NEWKEYP WORK i B_FIP1 Chattering counter
Use
Attributes SADDR SADDR SADDR SADDR SADDRP SADDR SADDR SADDR
Bytes 1 8 8 1 2 1 1 12
Previous key bit input storage area Current key bit input storage area Key scan data storage area Next key bit input storage area Key data transfer area Loop processing work counter Stores display data

Name F_KHENKA F_KEYEND
Use Set upon change in key input. Set when four keys are scanned.
1 level, 3 bytes * FIP controller/driver * Port 11 * Port 12 (P120 through P123) * Setting of DSPM0 DSPM0 = #00000000B ; Selects 9 segments * Setting of DSPM1 DSPM1 = #10110011B ; 12 display digits, digit signal cut width of 2/16, and display cycle of 488 s * Port 11 output mode PM11 = #00000000B * INTKS interrupt enable CLR1 KSMK The input key data is stored into the KEY1_NEW area after the processing of the INTKS interrupt. All keys are completely input after the INTKS interrupt request has occurred two times. The determined key is stored into the KEY1_OLD area.
269
78K/0 SERIES APPLICATION NOTE
* Set RAM as follows after reset and start: NEWKEYP = #KEY1_NEW ; key bit storage RAM address SCAN = #00000001B ; key scan data initial value * Input the key data after testing the key change flag. Because the key change flag is not cleared to 0 by interrupt processing, clear this flag after flag test. 10.1.4 Example of Use In the program example shown below, the initial setting of the key scan work area and display data conversion processing are performed for FIP display.
270
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER
EXTRN KEY1_OLD,KEY1_NEW,SCAN,NEWKEYP EXTBIT F_KHENKA ; FIP1 EQU 0FA70H ; B_FIP1: DS 12 M1 RES_STA: CSEG
; FIP display 1st digit output BUF ;
DI DSPM0=#00000000B DSPM1=#10110011B PM11=#00000000B CLR1 KSIF CLR1 KSMK ; SCAN=#00000001B NEWKEYP=#KEY1_NEW EI ; while(forever) IF_BIT(F_KHENKA) CLR1 F_KHENKA Decode processing for(B=#0;B<#12.B++) HL=#B_FIP1 X=[HL+B] A=#0 AX+=#DISPLAY HL=AX A=[HL] HL=#FIP1 [HL+B]=A next ; FIPDAT CSEG DISPLAY: DB 11111100B DB 01100000B DB 11011010B DB 11110010B DB 01100110B DB 10110110B DB 10111110B DB 11100000B DB 11111110B DB 11110110B DB 11101110B DB 00111110B DB 10011100B DB 01111010B DB 10011110B DB 10001110B END
; ; Selects 9 segments ; 12 display digits, cut width of 2/16, display cycle of 488 s ; Port 11 output mode ; Clears the interrupt request flag ; Enables INTKS interrupt ; Key scan data initial value ; ; INTKS interrupt (INT_KEY) started by enabled interrupt ; ; Key change flag set? ; Clears key change flag
; Converts 12 FIP display digits into output data and stores that ; data into the output BUF ; ; ; ; ; ; ; ; ; ;0 ;1 ;2 ;3 ;4 ;5 ;6 ;7 ;8 ;9 ;A ;B ;C ;D ;E ;F
271
78K/0 SERIES APPLICATION NOTE
10.1.5 SPD Chart [Key input processing (INTKS interrupt processing)]
INT_KEY THEN
if (during key scan timing) Selects bank 2 WORK <- #0 HL <- next key bit input storage RAM address for (i = # 0 ; i < # 4 ; i + + ) Port 11 <- SCAN Shifts SCAN bit 1 bit to left Key scan time wait processing Inputs key return data if (previous bit data current bit data) THEN Chattering counter <- #0FFH [HL] <- key return data Increments HL register NEWKYEP <- HL if (ends input of all keys) THEN Clears key END flag if (chattering elimination ends) THEN if (previously determined key currently determined key) THEN Sets key change flag Initializes chattering counter NEWKYEP <- NEW key bit input determination area SCAN <- key scan initial value if (during key scan timing) THEN Increments chattering counter ELSE Sets key END flag
272
CHAPTER 10 APPLICATIONS OF FIP CONTROLLER/DRIVER
10.1.6 Program Listing ;*********************************************** ; Key input processing (INTKS interrupt) ;*********************************************** ; $PC(044A) PUBLIC KEY1_OLD,KEY1_NEW,SCAN,NEWKEYP PUBLIC F-KHENKA ; VEINTKS CSEG AT 1CH DW INT_KEY ; CHATDAT EQU 02H ; Number of times chattering is eliminated SCANDAT EQU 00000001B ; First key scan data ; ;*********************************************** ; RAM definition ;*********************************************** ; KEYRAM DSEG SADDR KEY1_OLD: DS 8 ; Previous key bit input determination data area KEY1_NEW: DS 8 ; Current key bit input determination data area C_CHATA: DS 1 ; Chattering counter WORK: DS 1 ; Work area SCAN: DS 1 ; Key scan data storage area i: DS 1 ; Work counter area DSEG SADDRP NEWKEYP: DS 2 ; Next key bit input determination RAM address storage area ; KEYFLG BSEG F_KHENKA DBIT ; Key change flag F_KEYEND DBIT ; Key END flag ; KEY CSEG ; INT_KEY: IF_BIT(KSF) ; Checks flag of INTKS SEL RB2 ; Selects bank 2 WORK=#0 ; HL=NEWKEYP (AX) ; Stores next key storage RAM address into HL register for(i=#0;i<=#4;i++) ; P11=SCAN (A) ; Outputs key scan signal A=SCAN ; Shifts scan signal 1 bit to left ROL A,1 ; SCAN=A ; for(B=#0;B<#6;B++) (A) ; Scan time wait processing next ; A=P12 ; Key return input A &= #0FH ; WORK=A ; Stores key return to WORK area
273
78K/0 SERIES APPLICATION NOTE
if(A!=[HL]) C_CHATA=#0FFH endif [HL]=WORK (A) HL++ next NEWKEYP=HL (AX) if_bit(F_KEYEND) CLR1 F_KEYEND if(C_CHATA>#CHATDAT) DE=#KEY1_OLD HL=#KEY1_NEW for(i=#0;i<#8;i++) if([DE]!=[HL]) (A) SET1 F_KHENKA endif [DE]=[HL] (A) DE++ HL++ next C_CHATA=#0 NEWKEYP=#KEY1_NEW SCAN=#SCANDAT else if_bit(KSF) C_CHATA++ endif endif else SET1 endif ENDIF RETI END F_KEYEND
; ; Clears chattering counter unless the same as the previous ; value ; ; ; ; ; All keys input? ; ; End of chattering elimination? ; ; Previously determined key currently determined key? ; ; Sets key change flag ; ; ; ; ; ; ; Clears chattering counter ; Initializes next key bit input determination RAM address ; Initializes key scan data ; ; Checks INTKS flag ; Increments chattering counter if OK ; ; ; ; ; ; ;
274
CHAPTER 11 APPLICATIONS OF 6-BIT UP/DOWN COUNTER
CHAPTER 11 APPLICATIONS OF 6-BIT UP/DOWN COUNTER
The 6-bit up/down counter is incremented or decremented at the valid edge of the CI0/P03/INTP3 pin. This counter uses a 6-bit up/down register (UDC) to count the number of count pulses input to the CI0/P03/ INTP3 pin (see Figure 11-1). If the value of the UDC coincides with the value of a 6-bit up/down counter compare register (UDCC) in ascending count mode, an interrupt request flag (PIF3) is set, and the UDC is cleared to 0. If the UDC underflows in the descending count mode, the interrupt request flag (PIF3) is set, and a value of UDCC minus 1 is loaded into the UDC. The 6-bit up/down counter is controlled by a 6-bit up/down counter control register (UDM). Figure 11-1. Block Diagram of 6-Bit Up/Down Counter

6-bit up/down counter compare register (UDCC) Match
INTP3/INTUD interrupt request signal
CI0/P03/INPT3
6-bit up/down counter (UDC)
Clear

6-bit up/down counter compare register (UDCC)
-1
Load
CI0/P03/INPT3
6-bit up/down counter (UDC) Underflow
INTP3/INTUD interrupt request signal
Caution When using the 6-bit up/down counter, set the CI0/P03/INTP3 pin to input mode (by setting bit 3 (PM03) of port mode register 0 to 1).
275
78K/0 SERIES APPLICATION NOTE
Figure 11-2. Format of 6-Bit Up/Down Counter Control Register
Symbol UDM
7 0
6 0
5 0
4
3
2
1
0
Address FFA8H
At reset 00H
R/W R/W
UDM4 UDM3 UDM2 UDM1 UDM0
UDM0 Valid edge selection 0 1 Falling edge of CI0 Rising edge of CI0
UDM1 Operation mode selection 0 1 Descending count operation Ascending count operation
UDM2 Count operation control 0 1 Stops count operation (count value retained) Enables count operation
UDM3 Counter clearing 0 1 Count operation Clears counter
UDM4 Selection of setting signal for INTP3 flag 0 1 Set by INTP3 interrupt signal Set by INTUD interrupt signal
Cautions 1. Do not set UDM0, UDM1, and UDM3 at the same time as the input of the valid edge of the CI0/P03/INTP3 pin. 2. When 1 is written into UDM3, the UDC is cleared to 0. When the UDC is cleared, UDM3 is automatically reset to 0. 3. The UDC cannot be read or written until data is set in it after RESET.
276
CHAPTER 11 APPLICATIONS OF 6-BIT UP/DOWN COUNTER
11.1 1-SECOND COUNTER This section provides an example in which the 6-bit up/down counter generates an interrupt request every 1 second when an external frequency of 60 Hz is input to CI0. The interrupt processing increments or decrements a RAM counter (C_COUNT) by using a count direction flag (F_HOUKOU). (1) Description of package * Subroutine name S_UPDOWN: Subroutine incrementing/decrementing counter * Input parameter F_HOUKOU : Up/down count status DATAU : Data stored to compare register (frequency: 60 Hz) * Output parameter C_COUNT : Stores counter value None
Name C_COUNT
Use RAM counter
Attributes SADDR
Bytes 1

Name F_HOUKOU
Use Count direction flag (counter counts down when this flag is set)
2 levels, 5 bytes * 6-bit up/down counter * Set by subroutine S_UPDOWN * INTUD interrupt enabled * Counting is started when the INTUD interrupt request is enabled. * Call subroutine S_UPDOWN to change the count direction (between up and down). 277
78K/0 SERIES APPLICATION NOTE
(2) Example of use EXTRN S_UPDOWN.DATAU M2 CSEG RES_STA: DI UDC=#0 UDCC=#DATAU UDM=#00011110B CLR1 PIF3 CLR1 KSIF CLR1 PMK3 CLR1 KSMK EI if(up/down change) CALL !S_UPDOWN endif (3) SPD chart [Count processing (INTUD interrupt processing)]
COUNT if (counting in negative direction) THEN Decrements RAM counter ELSE Increments RAM counter
; ; ; ; ; ; ; ; ; ;
Clears 6-bit up/down counter Sets value to compare register up Set by INTUD interrupt signal. Ascending count operation. Clears INTP3 (INTUD) interrupt request flag Clears interrupt request flag Enables INTUD interrupt Enables INTKS interrupt
[Count direction change routine]
S_UPDOWN Stops 6-bit up/down counter if (down count direction) THEN UDCC <- selects down counter operation ELSE UDCC <- selects up counter operation Starts 6-bit up/down counter operation
278
CHAPTER 11 APPLICATIONS OF 6-BIT UP/DOWN COUNTER
(4) Program list ; ;*********************************************** ; 6-bit up/down counter (INTUD) ;*********************************************** $PC(044A) ; ; PUBLIC C_COUNT,F_HOUKOU ; PUBLIC S_UPDOWNU ; PUBLIC DATAU ; ; VEINTUD CSEG AT 0CH DW COUNT DATAU EQU 60 ; 60 Hz cycle ;*********************************************** ; RAM definition ;*********************************************** DSEG SADDR ; C_COUNT: DS 1 ; RAM counter BSEG ; F_HOUKOU DBIT ; Count direction flag ; CSEG ; COUNT: SEL RB2 ; if_bit(F_HOUKOU) ; Count direction flag = 1? C_COUNT-; yes -> decrements RAM counter else ; C_COUNT++ ; no -> increments RAM counter endif ; RETI ; ; ;*********************************************** ; RAM counter up/down subroutine ;*********************************************** S_UPDOWN: CLR1 UDM.2 ; Stops count operation if_bit(F_HOUKOU) ; CLR1 UDM.1 ; Down counter operation else ; SET1 UDM.1 ; Up counter operation endif ; SET1 UDM.2 ; Starts count operation RET ; END
279
78K/0 SERIES APPLICATION NOTE
[MEMO]
280
APPENDIX A SPD CHART DESCRIPTION
APPENDIX A SPD CHART DESCRIPTION
SPD is an acronym derived from Structured Programming Diagrams. "Structured" means logical design and organization using basic logical structures, and involves structuring the logical processes of a program. All programs can be created by only combining basic logical structures (sequencing, selection, repetition). (This is called the structured theorem.) Thus, the program flow is clarified by its structure and reliability improves. There are a variety of ways to represent program structure; however, a graphical technique called SPD is used at NEC. Below, the SPD symbols used in the SPD technique are described and compared to flowchart symbols. Table A-1. Comparison of SPD Symbols and Flowcharts (1/2)
Process name Sequential processing Process 1 Process 2 Process 2 SPD symbol Flowchart symbol
Process 1
Conditional branch (IF)
(IF : Condition) [THEN] Process 1 [ELSE] Process 2
Condition THEN Process 1
ELSE
Process 2
Conditional branch (SWITCH)
(SWITCH : Condition) [CASE : 1] Process 1 [CASE : 2] Process 2 * * * [CASE : n] Process n Process 1 Process 2 Process n Condition
281
78K/0 SERIES APPLICATION NOTE
Table A-1. Comparison of SPD Symbols and Flowcharts (2/2)
Process name Conditional loop (WHILE) Condition (WHILE : Condition) Process THEN Process ELSE SPD symbol Flowchart symbol
Conditional loop (UNTIL) (UNTIL : Condition) Process ELSE Process
Condition THEN
Conditional loop (FOR) Initial values
(FOR : Initial values; Condition; Increment or decrement setting) Process
Condition THEN Process Increment/ decrement
ELSE
Infinite loop (WHILE : forever) Process Process
Connector ( IF : Condition) [THEN] GOTO A Condition THEN A A Process Process ELSE A
282
APPENDIX A SPD CHART DESCRIPTION
1. Sequential Processing Sequential processing is executed in the output order from the top to the bottom. * SPD chart
Process 1 Process 2
2. Conditional Branch: 2 Branches (IF) The processing content is selected based on whether the condition specified in IF is true or false (THEN/ ELSE). * SPD chart
(IF : Condition) [THEN] Process 1 [ELSE] Process 2
Examples1. Determine whether X is positive or negative.
(IF : X > 0) [THEN] X is a positive number [ELSE] X is 0 or a negative number
2. If the signal is red, stop.
(IF : Signal = Red) [THEN] STOP
283
78K/0 SERIES APPLICATION NOTE
3. Conditional Branch: Multiple Branches (SWITCH) The condition specified by SWITCH is compared to the states indicated by CASE and the processing is selected. The two types of processing for a SWITCH statement are the case where only processing in the matched state is executed and the case where processing starts at the matched state and continues on below it. (When processing is not continued, `break' is written.) Also, when no condition is matched, `default' processing is executed (specifying `default' is optional). (1) For only the matched state * SPD chart
(Execution contents) (SWITCH : Condition) [CASE : State 1] Process 1 break [CASE : State 2] Process 2 * * * break * * * Process n [default] Process 0 When no state is matched : Process 0 In state 2 : Process 2 * * * * * * * * * * * * In state 1 : Process 1
[CASE : State n]
In state n : Process n
Example Display the name of a month by entering a character.
(SWITCH : input character) [CASE : `1'] Display Jan. break [CASE : `2'] Display Feb. * * * [default] break * * * Display ERROR
284
APPENDIX A SPD CHART DESCRIPTION
(2) For processing beginning at the matched state * SPD chart
(Execution contents) (SWITCH : Condition) [CASE : State 1] Process 1 [CASE : State 2] Process 2 * * * * * * [CASE : State n] Process n [default] Process 0 When no state is matched : Process 0 In state 2 : Process 2 ->***-> Process n * * * * * * * * * * * * In state n : Process n In state 1 : Process 1 -> Process 2 ->***-> Process n
Example Communication through a serial interface
(Execution contents) (SWITCH : Transfer mode) [CASE : 1] Address transmission [CASE : 2] Data transmission break [CASE : 3] Data reception In state 3 : Data reception In state 2 : Data transmission In state 1 : Address transmission -> Data transmission
4. Conditional Loop (WHILE) The condition specified in WHILE is evaluated. The processing is repeatedly executed as long as the condition holds. (When the condition does not hold from the beginning, nothing is executed.) * SPD chart
(WHILE : Condition) Processing
Example The keys are buffered until the RETURN key is input.
(WHILE : Not the RETURN key) Input one character key Store input key in buffer
285
78K/0 SERIES APPLICATION NOTE
5. Conditional Loop (UNTIL) The condition specified in UNTIL is evaluated after the process. The process is repeatedly executed until the condition holds. (Even when the condition does not hold at the beginning, the process is executed once.) * SPD chart
(UNTIL : Condition) Process
Example The value in register B is multiplied by 10 and saved in register A.
Initialize register A Set the value in register B Save 10 in the counter (UNTIL : Counter = 0) A= A+B Decrement the counter
6. Conditional Loop (FOR) The process is repeatedly executed until the parameter conditions specified in FOR hold. * SPD chart
(FOR : Initial values; Conditions; Increment/decrement settings) Process
Example Beginning at the HL address, clear 256 bytes to 0.
Set the start address in the HL register (FOR : WORKCT = #0 ; WORKCT < #256 ; WORKCT++) Clear the HL address to 0 Increment the HL register
286
APPENDIX A SPD CHART DESCRIPTION
7. Infinite Loop By specifying `forever' as the WHILE condition, the process is repeatedly executed forever. * SPD chart
(WHILE : forever) Process
Example Repeatedly execute the main processing.
(WHILE : forever) Main processing Save the key code in the display area. Decode key
8. Connector (GOTO) The specified address is unconditionally branched to. * SPD chart (1) Branch to the same module
(IF : Condition) [THEN] GOTO ERR * * * ERR Process
287
78K/0 SERIES APPLICATION NOTE
(2) Branch to different modules
(IF : Condition) [THEN] GOTO ERR (SUB_ER) : Module name
SUB_ER
Process * * *
ERR Process
Example At the starting address of the subroutine, the parameter is selected and a wait is set.
WAIT10 WAIT20 WAIT30 WAIT
Set register A to 10 GOTO WAIT Set register A to 20 GOTO WAIT Set register A to 30
(UNTIL : A = 0) Decrement A
9. Connector (Continue) When one SPD module lasts multiple pages, the processing flow is shown below. * SPD chart
Process 1 Process 2
1
Process 3 Process 4
1
288
APPENDIX B REVISION HISTORY
APPENDIX B REVISION HISTORY
The complete revision history is shown below. The applicable places are shown for the chapter in each edition.
Edition no. Version 2 Major revisions from the previous edition The following chapters and sections have been added: Sections 2.1 to 2.6, Chapters 3 to 7, Sections 8.1 to 8.4 and 9.1 to 9.3 The following subseries have been added as applicable products: PD78024, PD78044A, and PD780208 The following subseries are no longer applicable products: PD78002, PD78002Y, PD78014, and PD78014Y subseries (These subseries are described in Basics (I).) PD78044 Subseries PD78054 and PD78064 subseries (These subseries are described in Basics (III).) "Configuration of 12-Digit FIP Display and Key Input" has been changed. Version 3 The following products have been added as applicable products: PD78044F, PD78044H, and PD780228 subseries, PD780206, and PD780208 The following subseries have been dropped as applicable products: PD78024 and PD78044A subseries The following subseries have been added in Section 1.1. Chapter 1 PD78075B, PD78075BY, PD780018, PD780018Y, PD780058, PD780058Y, PD78058F, PD78058FY, PD780034, PD780034Y, PD780024, PD780024Y, PD78014H, PD780964, PD780924, PD780228, PD78044H, PD78044F, PD780308, PD780308Y, PD78064B, PD78098B, PD780973, and PD780805 subseries, and PD78P0914 Table 3-3 has been added. Note 2 and Caution 2 have been added to Figure 4-2. Figure 4-4 has been added. A Caution has been added to Figure 5-5. Table 8-2 has been added. Note 4 and a Caution have been added to Figure 8-3. A Caution has been added to Figure 8-9. Section 8.1 The PD6252 has been defined as a product provided for maintenance purposes only. Figure 9-4 has been added. Chapter 9 Chapter 5 Chapter 8 Chapter 3 Chapter 4 Chapter 10 Throughout Applicable chapters Throughout
289
78K/0 SERIES APPLICATION NOTE
[MEMO]
290
Facsimile Message
From:
Name Company
Although NEC has taken all possible steps to ensure that the documentation supplied to our customers is complete, bug free and up-to-date, we readily accept that errors may occur. Despite all the care and precautions we've taken, you may encounter problems in the documentation. Please complete this form whenever you'd like to report errors or suggest improvements to us.
Tel.
FAX
Address
Thank you for your kind support.
North America Hong Kong, Philippines, Oceania NEC Electronics Inc. NEC Electronics Hong Kong Ltd. Corporate Communications Dept. Fax: +852-2886-9022/9044 Fax: 1-800-729-9288 1-408-588-6130 Korea Europe NEC Electronics Hong Kong Ltd. NEC Electronics (Europe) GmbH Seoul Branch Technical Documentation Dept. Fax: 02-528-4411 Fax: +49-211-6503-274 South America NEC do Brasil S.A. Fax: +55-11-889-1689 Taiwan NEC Electronics Taiwan Ltd. Fax: 02-719-5951 Asian Nations except Philippines NEC Electronics Singapore Pte. Ltd. Fax: +65-250-3583
Japan NEC Corporation Semiconductor Solution Engineering Division Technical Information Support Dept. Fax: 044-548-7900
I would like to report the following error/make the following suggestion: Document title: Document number: Page number:
If possible, please fax the referenced page or drawing. Document Rating Clarity Technical Accuracy Organization Excellent Good Acceptable Poor
CS 96.8


▲Up To Search▲   

 
Price & Availability of UPD78042F

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X